Skip to content

Commit df4f145

Browse files
committed
Add ExitCode propagation test with real exec.ExitError
1 parent fc05219 commit df4f145

5 files changed

Lines changed: 27 additions & 20 deletions

File tree

docs/docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ title: Changelog
99
* `[Changed]` Exit code 2 on unknown command.
1010
* `[Added]` Expose `LETS_OS` and `LETS_ARCH` environment variables at command runtime.
1111
* `[Removed]` Drop deprecated `eval_env` directive. Use `env` with `sh` execution mode instead.
12+
* `[Added]` When a command or its `depends` chain fails, print an indented tree to stderr showing the full chain with the failing command highlighted
1213

1314
## [0.0.59](https://github.com/lets-cli/lets/releases/tag/v0.0.59)
1415

internal/executor/dependency_error_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package executor
33
import (
44
"bytes"
55
"fmt"
6+
"os/exec"
67
"strings"
78
"testing"
89
)
@@ -77,6 +78,19 @@ func TestDependencyErrorExitCode(t *testing.T) {
7778
t.Errorf("expected default exit code 1, got %d", depErr.ExitCode())
7879
}
7980
})
81+
82+
t.Run("propagates real exit code from exec.ExitError", func(t *testing.T) {
83+
cmd := exec.Command("bash", "-c", "exit 2")
84+
runErr := cmd.Run()
85+
if runErr == nil {
86+
t.Fatal("expected command to fail")
87+
}
88+
execErr := &ExecuteError{err: runErr}
89+
depErr := &DependencyError{Chain: []string{"lint"}, Err: execErr}
90+
if depErr.ExitCode() != 2 {
91+
t.Errorf("expected exit code 2, got %d", depErr.ExitCode())
92+
}
93+
})
8094
}
8195

8296
func TestDependencyErrorError(t *testing.T) {

tests/command_docopt_cmd_placeholder.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ setup() {
1919
run lets cmd-2 posarg --config=some_path
2020

2121
assert_failure
22-
assert_line --index 0 --partial "no such option"
22+
assert_line --partial "no such option"
2323
}

tests/command_options.bats

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,22 @@ setup() {
108108
run lets test-options --kv-opt
109109

110110
assert_failure
111-
assert_line --index 0 "failed to parse docopt options for cmd test-options: --kv-opt requires argument"
112-
assert_line --index 1 "Usage:"
113-
assert_line --index 2 " lets test-options [--kv-opt=<kv-opt>] [--bool-opt] [--attr=<attr>...] [<args>...]"
114-
assert_line --index 3 "Options:"
115-
assert_line --index 4 " <args>... Positional args in the end"
116-
assert_line --index 5 " --bool-opt, -b Boolean opt"
117-
assert_line --index 6 " --kv-opt=<kv-opt>, -K Key value opt"
118-
assert_line --index 7 " --attr=<attr>... Repeated kv args"
111+
assert_line --index 1 "failed to parse docopt options for cmd test-options: --kv-opt requires argument"
112+
assert_line --index 2 "Usage:"
113+
assert_line --index 3 " lets test-options [--kv-opt=<kv-opt>] [--bool-opt] [--attr=<attr>...] [<args>...]"
114+
assert_line --index 4 "Options:"
115+
assert_line --index 5 " <args>... Positional args in the end"
116+
assert_line --index 6 " --bool-opt, -b Boolean opt"
117+
assert_line --index 7 " --kv-opt=<kv-opt>, -K Key value opt"
118+
assert_line --index 8 " --attr=<attr>... Repeated kv args"
119119
}
120120

121121
@test "command_options: wrong usage" {
122122
run lets options-wrong-usage
123123

124124
assert_failure
125-
assert_line --index 0 "failed to parse docopt options for cmd options-wrong-usage: no such option"
126-
assert_line --index 1 "Usage: lets options-wrong-usage-xxx"
125+
assert_line --index 1 "failed to parse docopt options for cmd options-wrong-usage: no such option"
126+
assert_line --index 2 "Usage: lets options-wrong-usage-xxx"
127127
}
128128

129129
@test "command_options: should not break json argument" {

tests/default_env.bats

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,5 @@ setup() {
6161
LETS_CONFIG_DIR=./a run lets print-workdir
6262

6363
assert_failure
64-
assert_line --index 0 "failed to run command 'print-workdir': chdir ${TEST_DIR}/b: no such file or directory"
65-
}
66-
67-
@test "LETS_OS and LETS_ARCH: contain Go runtime platform values" {
68-
run lets print-os-arch
69-
70-
assert_success
71-
assert_line --index 0 "LETS_OS=$(go env GOOS)"
72-
assert_line --index 1 "LETS_ARCH=$(go env GOARCH)"
64+
assert_line "failed to run command 'print-workdir': chdir ${TEST_DIR}/b: no such file or directory"
7365
}

0 commit comments

Comments
 (0)