Skip to content

Commit f73a374

Browse files
committed
test: make Bats tests self-contained (no external helpers)
1 parent 137e785 commit f73a374

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

test/completion.bats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
run zsh -c '
88
export DEV_ROOT="'"$fake_root"'"
99
source "$BATS_TEST_DIRNAME/../proj-jumper.plugin.zsh"
10-
reply=() # zsh completions are returned in $reply
11-
_proj_complete "" # call the completion function
10+
reply=()
11+
_proj_complete "" # populate $reply
1212
print -l "${reply[@]}"
1313
'
1414

15-
[ "$status" -eq 0 ]
16-
[[ "$output" == *"alpha"* ]]
17-
[[ "$output" == *"beta"* ]]
15+
[ \"$status\" -eq 0 ]
16+
[[ \"$output\" == *alpha* ]]
17+
[[ \"$output\" == *beta* ]]
1818
}

test/proj_config_sets_root.bats

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@test "proj-config appends PROJ_DEV_ROOT export to .zshrc" {
44
temp_home="$(mktemp -d)"
5-
export ZDOTDIR="$temp_home" # make plugin look here for .zshrc
5+
export ZDOTDIR="$temp_home"
66
touch "$ZDOTDIR/.zshrc"
77

88
new_root="$(mktemp -d)"
@@ -12,9 +12,6 @@
1212
proj-config "'"$new_root"'"
1313
'
1414

15-
# command succeeds
16-
[ "$status" -eq 0 ]
17-
18-
# line actually added
19-
grep -q "export PROJ_DEV_ROOT=$new_root" "$ZDOTDIR/.zshrc"
15+
[ \"$status\" -eq 0 ]
16+
grep -q \"export PROJ_DEV_ROOT=$new_root\" \"\$ZDOTDIR/.zshrc\"
2017
}

test/proj_help.bats

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env bats
22

3-
setup() {
4-
load '../test_helpers/load_plugin' # tiny helper that sources the plugin
5-
}
6-
73
@test "proj --help prints usage" {
8-
run proj --help
9-
[ "$status" -eq 0 ]
10-
[[ "$output" == *"Usage:"* ]]
4+
run zsh -c "
5+
source \"\$BATS_TEST_DIRNAME/../proj-jumper.plugin.zsh\"
6+
proj --help
7+
"
8+
[ \"$status\" -eq 0 ]
9+
[[ \"$output\" == *'Usage:'* ]]
1110
}

test/proj_root_missing.bats

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#!/usr/bin/env bats
22

3-
load 'test_helper/bats-support/load' # optional if bats-support is available
4-
load 'test_helper/bats-assert/load' # optional if bats-assert is available
5-
63
@test "proj warns and exits 1 when DEV_ROOT is missing" {
74
missing_root="$(mktemp -d)"
8-
rmdir "$missing_root" # ensure the directory truly does not exist
5+
rmdir "$missing_root"
96

107
run zsh -c "
118
export DEV_ROOT='$missing_root'
129
source \"\$BATS_TEST_DIRNAME/../proj-jumper.plugin.zsh\"
1310
proj
1411
"
1512

16-
[ "$status" -eq 1 ]
17-
[[ "$output" == ⚠️* ]] || [[ "$output" == *'not found'* ]]
13+
[ \"\$status\" -eq 1 ]
14+
[[ \"\$output\" == ⚠️* ]] || [[ \"\$output\" == *'not found'* ]]
1815
}

test/proj_unknown_project.bats

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#!/usr/bin/env bats
22

3-
load 'test_helper/bats-support/load' # optional
4-
load 'test_helper/bats-assert/load' # optional
5-
63
@test "proj exits 1 and warns when project does not exist" {
74
fake_root="$(mktemp -d)"
8-
mkdir "$fake_root/alpha" # a real directory to prove root exists
5+
mkdir "$fake_root/alpha"
96

107
run zsh -c "
118
export DEV_ROOT='$fake_root'
12-
source \"$BATS_TEST_DIRNAME/../proj-jumper.plugin.zsh\"
9+
source \"\$BATS_TEST_DIRNAME/../proj-jumper.plugin.zsh\"
1310
proj doesnotexist
1411
"
1512

16-
[ "$status" -eq 1 ]
17-
[[ "$output" == *'No such project'* ]]
13+
[ \"\$status\" -eq 1 ]
14+
[[ \"\$output\" == *'No such project'* ]]
1815
}

0 commit comments

Comments
 (0)