11package integration
22
33import (
4+ "errors"
45 "fmt"
56 "os"
67 "os/exec"
78 "path/filepath"
8- "runtime"
99 "testing"
1010)
1111
1212func TestGPS (t * testing.T ) {
13- var notFoundMsg string
14- if runtime .GOOS == "windows" {
15- notFoundMsg = "The system cannot find the path specified."
16- } else {
17- notFoundMsg = "no such file or directory"
18- }
1913 tests := []struct {
2014 dir string
2115 input []string
2216 expected string
2317 environ []string
18+ err error
2419 }{
25- {"bare" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 BARE:main\x1b [0m" , nil },
26- {"no_upstream" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 main\x1b [0m" , nil },
27- {"no_upstream_remote" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 main → mikesmithgh/test/main\x1b [0m" , nil },
28- {"git_dir" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 GIT_DIR!\x1b [0m" , nil },
29- {"clean" , []string {"--config=NONE" }, "\x1b [32m \ue0a0 main\x1b [0m" , nil },
30- {"tag" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 (v1.0.0)\x1b [0m" , nil },
31- {"commit" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 (24afc95)\x1b [0m" , nil },
32- {"dirty" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main *\x1b [0m" , nil },
33- {"dirty_staged" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main *\x1b [0m" , nil },
34- {"conflict_ahead" , []string {"--config=NONE" }, "\x1b [33m \ue0a0 main ↑[1]\x1b [0m" , nil },
35- {"conflict_behind" , []string {"--config=NONE" }, "\x1b [33m \ue0a0 main ↓[1]\x1b [0m" , nil },
36- {"conflict_diverged" , []string {"--config=NONE" }, "\x1b [33m \ue0a0 main ↕ ↑[1] ↓[1]\x1b [0m" , nil },
37- {"untracked" , []string {"--config=NONE" }, "\x1b [35m \ue0a0 main *\x1b [0m" , nil },
38- {"sparse" , []string {"--config=NONE" }, "\x1b [32m \ue0a0 main|SPARSE\x1b [0m" , nil },
39- {"sparse_merge_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|SPARSE|MERGING|CONFLICT *↕ ↑[1] ↓[1]\x1b [0m" , nil },
20+ {"bare" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 BARE:main\x1b [0m" , nil , nil },
21+ {"no_upstream" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 main\x1b [0m" , nil , nil },
22+ {"no_upstream_remote" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 main → mikesmithgh/test/main\x1b [0m" , nil , nil },
23+ {"git_dir" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 GIT_DIR!\x1b [0m" , nil , nil },
24+ {"clean" , []string {"--config=NONE" }, "\x1b [32m \ue0a0 main\x1b [0m" , nil , nil },
25+ {"tag" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 (v1.0.0)\x1b [0m" , nil , nil },
26+ {"commit" , []string {"--config=NONE" }, "\x1b [90m \ue0a0 (24afc95)\x1b [0m" , nil , nil },
27+ {"dirty" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main *\x1b [0m" , nil , nil },
28+ {"dirty_staged" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main *\x1b [0m" , nil , nil },
29+ {"conflict_ahead" , []string {"--config=NONE" }, "\x1b [33m \ue0a0 main ↑[1]\x1b [0m" , nil , nil },
30+ {"conflict_behind" , []string {"--config=NONE" }, "\x1b [33m \ue0a0 main ↓[1]\x1b [0m" , nil , nil },
31+ {"conflict_diverged" , []string {"--config=NONE" }, "\x1b [33m \ue0a0 main ↕ ↑[1] ↓[1]\x1b [0m" , nil , nil },
32+ {"untracked" , []string {"--config=NONE" }, "\x1b [35m \ue0a0 main *\x1b [0m" , nil , nil },
33+ {"sparse" , []string {"--config=NONE" }, "\x1b [32m \ue0a0 main|SPARSE\x1b [0m" , nil , nil },
34+ {"sparse_merge_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|SPARSE|MERGING|CONFLICT *↕ ↑[1] ↓[1]\x1b [0m" , nil , nil },
4035
4136 // rebase merge
42- {"rebase_i" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|REBASE-i 1/1\x1b [0m" , nil },
43- {"rebase_m" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|REBASE-m 1/1\x1b [0m" , nil },
37+ {"rebase_i" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|REBASE-i 1/1\x1b [0m" , nil , nil },
38+ {"rebase_m" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|REBASE-m 1/1\x1b [0m" , nil , nil },
4439 // rebase apply
45- {"am_rebase" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 (b69e688)|AM/REBASE 1/1\x1b [0m" , nil },
46- {"am" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 (b69e688)|AM 1/1\x1b [0m" , nil },
47- {"rebase" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|REBASE 1/1\x1b [0m" , nil },
40+ {"am_rebase" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 (b69e688)|AM/REBASE 1/1\x1b [0m" , nil , nil },
41+ {"am" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 (b69e688)|AM 1/1\x1b [0m" , nil , nil },
42+ {"rebase" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|REBASE 1/1\x1b [0m" , nil , nil },
4843 // merge
49- {"merge_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|MERGING|CONFLICT *↕ ↑[1] ↓[1]\x1b [0m" , nil },
50- {"merge" , []string {"--config=NONE" }, "\x1b [35m \ue0a0 main|MERGING *↕ ↑[1] ↓[1]\x1b [0m" , nil },
44+ {"merge_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|MERGING|CONFLICT *↕ ↑[1] ↓[1]\x1b [0m" , nil , nil },
45+ {"merge" , []string {"--config=NONE" }, "\x1b [35m \ue0a0 main|MERGING *↕ ↑[1] ↓[1]\x1b [0m" , nil , nil },
5146 // cherry pick
52- {"cherry_pick_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|CHERRY-PICKING|CONFLICT *↕ ↑[1] ↓[1]\x1b [0m" , nil },
53- {"cherry_pick" , []string {"--config=NONE" }, "\x1b [35m \ue0a0 main|CHERRY-PICKING *↕ ↑[1] ↓[1]\x1b [0m" , nil },
47+ {"cherry_pick_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|CHERRY-PICKING|CONFLICT *↕ ↑[1] ↓[1]\x1b [0m" , nil , nil },
48+ {"cherry_pick" , []string {"--config=NONE" }, "\x1b [35m \ue0a0 main|CHERRY-PICKING *↕ ↑[1] ↓[1]\x1b [0m" , nil , nil },
5449 // revert
55- {"revert_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|REVERTING|CONFLICT *↕ ↑[2] ↓[1]\x1b [0m" , nil },
56- {"revert" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|REVERTING *↕ ↑[2] ↓[1]\x1b [0m" , nil },
50+ {"revert_conflict" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|REVERTING|CONFLICT *↕ ↑[2] ↓[1]\x1b [0m" , nil , nil },
51+ {"revert" , []string {"--config=NONE" }, "\x1b [31m \ue0a0 main|REVERTING *↕ ↑[2] ↓[1]\x1b [0m" , nil , nil },
5752 // bisect
58- {"bisect" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|BISECTING ↓[1]\x1b [0m" , nil },
53+ {"bisect" , []string {"--config=NONE" }, "\x1b [34m \ue0a0 main|BISECTING ↓[1]\x1b [0m" , nil , nil },
5954
6055 // formatting
61- {"clean" , []string {"--config=NONE" , "--color-disabled" }, " \ue0a0 main" , nil },
62- {"clean" , []string {"--config=NONE" , "--color-disabled" , "--prompt-prefix= start " }, " start main" , nil },
63- {"clean" , []string {"--config=NONE" , "--color-disabled" , "--prompt-suffix= stop" }, " \ue0a0 main stop" , nil },
64- {"conflict_ahead" , []string {"--config=NONE" , "--color-disabled" , "--ahead-format=ahead by %d" }, " \ue0a0 main ahead by 1" , nil },
65- {"conflict_behind" , []string {"--config=NONE" , "--color-disabled" , "--behind-format=behind by %d" }, " \ue0a0 main behind by 1" , nil },
66- {"conflict_diverged" , []string {"--config=NONE" , "--color-disabled" , "--diverged-format=ahead by %d behind by %d" }, " \ue0a0 main ahead by 1 behind by 1" , nil },
67- {"no_upstream_remote" , []string {"--config=NONE" , "--color-disabled" , "--no-upstream-remote-format= upstream=[repo: %s branch: %s]" }, " \ue0a0 main upstream=[repo: mikesmithgh/test branch: main]" , nil },
56+ {"clean" , []string {"--config=NONE" , "--color-disabled" }, " \ue0a0 main" , nil , nil },
57+ {"clean" , []string {"--config=NONE" , "--color-disabled" , "--prompt-prefix= start " }, " start main" , nil , nil },
58+ {"clean" , []string {"--config=NONE" , "--color-disabled" , "--prompt-suffix= stop" }, " \ue0a0 main stop" , nil , nil },
59+ {"conflict_ahead" , []string {"--config=NONE" , "--color-disabled" , "--ahead-format=ahead by %d" }, " \ue0a0 main ahead by 1" , nil , nil },
60+ {"conflict_behind" , []string {"--config=NONE" , "--color-disabled" , "--behind-format=behind by %d" }, " \ue0a0 main behind by 1" , nil , nil },
61+ {"conflict_diverged" , []string {"--config=NONE" , "--color-disabled" , "--diverged-format=ahead by %d behind by %d" }, " \ue0a0 main ahead by 1 behind by 1" , nil , nil },
62+ {"no_upstream_remote" , []string {"--config=NONE" , "--color-disabled" , "--no-upstream-remote-format= upstream=[repo: %s branch: %s]" }, " \ue0a0 main upstream=[repo: mikesmithgh/test branch: main]" , nil , nil },
6863
6964 // color overrides
70- {"clean" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [38;2;230;238;4m \ue0a0 main\x1b [0m" , nil },
71- {"no_upstream" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [30m\x1b [47m \ue0a0 main\x1b [0m" , nil },
72- {"dirty" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [48;2;179;5;89m \ue0a0 main *\x1b [0m" , nil },
73- {"conflict_ahead" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [38;2;252;183;40m \ue0a0 main ↑[1]\x1b [0m" , nil },
74- {"untracked" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [38;2;255;0;0m\x1b [48;2;22;242;170m \ue0a0 main *\x1b [0m" , nil },
75- {"bisect" , []string {}, "\x1b [48;2;204;204;255m\x1b [35m \ue0a0 main|BISECTING ↓[1]\x1b [0m" , []string {"GIT_PROMPT_STRING_CONFIG=../configs/color_overrides.toml" }},
65+ {"clean" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [38;2;230;238;4m \ue0a0 main\x1b [0m" , nil , nil },
66+ {"no_upstream" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [30m\x1b [47m \ue0a0 main\x1b [0m" , nil , nil },
67+ {"dirty" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [48;2;179;5;89m \ue0a0 main *\x1b [0m" , nil , nil },
68+ {"conflict_ahead" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [38;2;252;183;40m \ue0a0 main ↑[1]\x1b [0m" , nil , nil },
69+ {"untracked" , []string {"--config=../configs/color_overrides.toml" }, "\x1b [38;2;255;0;0m\x1b [48;2;22;242;170m \ue0a0 main *\x1b [0m" , nil , nil },
70+ {"bisect" , []string {}, "\x1b [48;2;204;204;255m\x1b [35m \ue0a0 main|BISECTING ↓[1]\x1b [0m" , []string {"GIT_PROMPT_STRING_CONFIG=../configs/color_overrides.toml" }, nil },
7671
7772 // config errors
78- {"clean" , []string {"--config=/fromparam/does/not/exist" }, fmt .Sprintf ("\x1b [31m git-prompt-string error(read config): open /fromparam/does/not/exist: %s\x1b [0m" , notFoundMsg ), nil },
79- {"configs" , []string {}, fmt .Sprintf ("\x1b [31m git-prompt-string error(read config): open /fromenvvar/does/not/exist: %s\x1b [0m" , notFoundMsg ), []string {"GIT_PROMPT_STRING_CONFIG=/fromenvvar/does/not/exist" }},
80- {"configs" , []string {"--config=invalid_syntax.toml" }, "\x1b [31m git-prompt-string error(unmarshal config): toml: expected character = \ x1b [0m" , nil },
81- {"configs" , []string {}, "\x1b [31m git-prompt-string error(unmarshal config): toml: expected character = \ x1b [0m" , []string {"GIT_PROMPT_STRING_CONFIG=invalid_syntax.toml" }},
73+ {"clean" , []string {"--config=/fromparam/does/not/exist" }, fmt .Sprintf ("\x1b [31m git-prompt-string error(read config): \" open /fromparam/does/not/exist: %s\" \ x1b [0m" , notFoundMsg ), nil , errors . New ( "exit status 1" ) },
74+ {"configs" , []string {}, fmt .Sprintf ("\x1b [31m git-prompt-string error(read config): \" open /fromenvvar/does/not/exist: %s\" \ x1b [0m" , notFoundMsg ), []string {"GIT_PROMPT_STRING_CONFIG=/fromenvvar/does/not/exist" }, errors . New ( "exit status 1" ) },
75+ {"configs" , []string {"--config=invalid_syntax.toml" }, fmt . Sprintf ( "\x1b [31m git-prompt-string error(unmarshal config): \" toml: expected character %s \" \ x1b [0m" , escapedEqualSign ), nil , errors . New ( "exit status 1" ) },
76+ {"configs" , []string {}, fmt . Sprintf ( "\x1b [31m git-prompt-string error(unmarshal config): \" toml: expected character %s \" \ x1b [0m" , escapedEqualSign ), []string {"GIT_PROMPT_STRING_CONFIG=invalid_syntax.toml" }, errors . New ( "exit status 1" ) },
8277
83- {"norepo" , []string {"--config=NONE" }, "" , nil },
78+ {"norepo" , []string {"--config=NONE" }, "" , nil , nil },
8479 }
8580
8681 for _ , test := range tests {
@@ -91,8 +86,10 @@ func TestGPS(t *testing.T) {
9186 cmd .Env = append (cmd .Env , test .environ ... )
9287 }
9388 result , err := cmd .CombinedOutput ()
94- if err != nil {
89+ if test . err == nil && err != nil {
9590 t .Errorf ("Unexpected error: %s" , err )
91+ } else if test .err != nil && test .err .Error () != err .Error () {
92+ t .Errorf ("Expected error: %s, got: %s" , test .err , err )
9693 }
9794 actual := string (result )
9895 if actual != test .expected {
0 commit comments