1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-20 05:19:24 +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
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
cmdOutput := []string{}
canAsk := true
splitCmd := ToArgv(command)
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.Split(bufio.ScanWords)
for scanner.Scan() {
toOutput := re.ReplaceAllString(scanner.Text(), "")
cmdOutput = append(cmdOutput, toOutput)
toWrite := output(toOutput)
if len(toWrite) > 0 {
_, _ = tty.Write([]byte(toWrite + "\n"))
// canAsk prefrents calls to output when the program is already closed
if canAsk {
toOutput := re.ReplaceAllString(scanner.Text(), "")
cmdOutput = append(cmdOutput, toOutput)
toWrite := output(toOutput)
if len(toWrite) > 0 {
_, _ = tty.Write([]byte(toWrite + "\n"))
}
}
}
waitForBufio.Done()
}()
if err := cmd.Wait(); err != nil {
canAsk = false
//
waitForBufio.Wait()
return strings.Join(cmdOutput, " "), err
}

View File

@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"strings"
"testing"
"time"
@ -983,7 +982,7 @@ func TestGitCommandPush(t *testing.T) {
},
false,
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,
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,
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 {
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)
})
}