Skip to content

Commit dff7f1b

Browse files
committed
new: Fix load environment path for --test
Previously tests created at the top-level of `_GO_TEST_DIR` would contain the line `load ../environment` when it should've been `load environment`. Also updates a misnamed test case in the same file.
1 parent b136f38 commit dff7f1b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

libexec/new

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ _@go.new_test() {
226226
local parent_dir="${test_relpath%/*}"
227227
local impl
228228

229-
if [[ -n "$parent_dir" ]]; then
229+
if [[ "$parent_dir" == "${test_path##*/}" ]]; then
230+
parent_dir=''
231+
else
230232
parent_dir="${parent_dir//[^\/]}/"
231233
fi
232234

tests/new.bats

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,14 @@ assert_command_script_is_executable() {
431431
$'\n@test "\$SUITE: short description of your first test case" \{\n'
432432
}
433433

434-
@test "$SUITE: --test fails if public module already exists" {
434+
@test "$SUITE: no '../' in environment load path for top-level test" {
435+
run "$TEST_GO_SCRIPT" new --test foo
436+
assert_success "EDITING: $TEST_GO_ROOTDIR/$_GO_TEST_DIR/foo.bats"
437+
assert_file_matches "$TEST_GO_ROOTDIR/$_GO_TEST_DIR/foo.bats" \
438+
$'\nload environment\n'
439+
}
440+
441+
@test "$SUITE: --test fails if test already exists" {
435442
run "$TEST_GO_SCRIPT" new --test foo/bar/baz
436443
assert_success "EDITING: $TEST_GO_ROOTDIR/$_GO_TEST_DIR/foo/bar/baz.bats"
437444
run "$TEST_GO_SCRIPT" new --test foo/bar/baz

0 commit comments

Comments
 (0)