1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

Fixed test

This commit is contained in:
mjarkk
2018-11-03 09:12:45 +01:00
parent af54d7f015
commit 8469239d84
2 changed files with 15 additions and 18 deletions

View File

@ -20,6 +20,7 @@ import (
// NOTE: You don't have to include a enter in the return data this function will do that for you // NOTE: You don't have to include a enter in the return data this function will do that for you
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) { func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
cmdOutput := []string{} cmdOutput := []string{}
canAsk := true
splitCmd := ToArgv(command) splitCmd := ToArgv(command)
cmd := exec.Command(splitCmd[0], splitCmd[1:]...) cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
@ -48,17 +49,23 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
scanner := bufio.NewScanner(tty) scanner := bufio.NewScanner(tty)
scanner.Split(bufio.ScanWords) scanner.Split(bufio.ScanWords)
for scanner.Scan() { for scanner.Scan() {
toOutput := re.ReplaceAllString(scanner.Text(), "") // canAsk prefrents calls to output when the program is already closed
cmdOutput = append(cmdOutput, toOutput) if canAsk {
toWrite := output(toOutput) toOutput := re.ReplaceAllString(scanner.Text(), "")
if len(toWrite) > 0 { cmdOutput = append(cmdOutput, toOutput)
_, _ = tty.Write([]byte(toWrite + "\n")) toWrite := output(toOutput)
if len(toWrite) > 0 {
_, _ = tty.Write([]byte(toWrite + "\n"))
}
} }
} }
waitForBufio.Done() waitForBufio.Done()
}() }()
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
canAsk = false
//
waitForBufio.Wait() waitForBufio.Wait()
return strings.Join(cmdOutput, " "), err return strings.Join(cmdOutput, " "), err
} }

View File

@ -5,7 +5,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"strings"
"testing" "testing"
"time" "time"
@ -983,7 +982,7 @@ func TestGitCommandPush(t *testing.T) {
}, },
false, false,
func(err error) { func(err error) {
assert.Nil(t, err) assert.Equal(t, "exit status 128", err.Error())
}, },
}, },
{ {
@ -996,7 +995,7 @@ func TestGitCommandPush(t *testing.T) {
}, },
true, true,
func(err error) { func(err error) {
assert.Nil(t, err) assert.Equal(t, "exit status 128", err.Error())
}, },
}, },
{ {
@ -1009,7 +1008,7 @@ func TestGitCommandPush(t *testing.T) {
}, },
false, false,
func(err error) { func(err error) {
assert.Nil(t, err) assert.Equal(t, "exit status 128", err.Error())
}, },
}, },
} }
@ -1021,15 +1020,6 @@ func TestGitCommandPush(t *testing.T) {
err := gitCmd.Push("test", s.forcePush, func(passOrUname string) string { err := gitCmd.Push("test", s.forcePush, func(passOrUname string) string {
return "-" return "-"
}) })
errMessage := err.Error()
cutrange := 43
if len(errMessage) < 43 {
cutrange = len(errMessage)
}
testMessage := errMessage[:cutrange]
if strings.Contains("error: src refspec test does not match any.", testMessage) {
err = nil
}
s.test(err) s.test(err)
}) })
} }