Skip to content

test_e2e.sh: quote variables to prevent globbing and word splitting #892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 99 additions & 99 deletions test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function assert_link_basename_eq() {
if [[ $(basename $(readlink "$1")) == "$2" ]]; then
return
fi
fail "$1 does not point to $2: $(readlink $1)"
fail "$1 does not point to $2: $(readlink "$1")"
}

function assert_file_exists() {
Expand All @@ -91,14 +91,14 @@ function assert_file_eq() {
if [[ $(cat "$1") == "$2" ]]; then
return
fi
fail "$1 does not contain '$2': $(cat $1)"
fail "$1 does not contain '$2': $(cat "$1")"
}

function assert_file_contains() {
if grep -q "$2" "$1"; then
return
fi
fail "$1 does not contain '$2': $(cat $1)"
fail "$1 does not contain '$2': $(cat "$1")"
}

function assert_file_lines_eq() {
Expand Down Expand Up @@ -761,9 +761,9 @@ function e2e::stale_worktree_timeout() {

# wait for first sync
wait_for_sync "${MAXWAIT}"
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$FUNCNAME 1"
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"

# wait 2 seconds and make another commit
sleep 2
Expand All @@ -776,11 +776,11 @@ function e2e::stale_worktree_timeout() {
wait_for_sync "${MAXWAIT}"
# at this point both WT1 and WT2 should exist, with
# link pointing to the new WT2
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"

# wait 2 seconds and make a third commit
sleep 2
Expand All @@ -793,57 +793,57 @@ function e2e::stale_worktree_timeout() {

# at this point WT1, WT2, WT3 should exist, with
# link pointing to WT3
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/link/file3
assert_file_exists "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_file_absent "$ROOT"/.worktrees/$WT1/file3
assert_file_exists "$ROOT"/.worktrees/$WT2/file
assert_file_exists "$ROOT"/.worktrees/$WT2/file2
assert_file_absent "$ROOT"/.worktrees/$WT2/file3
assert_file_exists "$ROOT"/.worktrees/$WT3/file
assert_file_exists "$ROOT"/.worktrees/$WT3/file2
assert_file_exists "$ROOT"/.worktrees/$WT3/file3
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/link/file3"
assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT/.worktrees/$WT3/file3"

# wait for WT1 to go stale
sleep 4

# now WT1 should be stale and deleted,
# WT2 and WT3 should still exist
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/link/file3
assert_file_absent "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_file_absent "$ROOT"/.worktrees/$WT1/file3
assert_file_exists "$ROOT"/.worktrees/$WT2/file
assert_file_exists "$ROOT"/.worktrees/$WT2/file2
assert_file_absent "$ROOT"/.worktrees/$WT2/file3
assert_file_exists "$ROOT"/.worktrees/$WT3/file
assert_file_exists "$ROOT"/.worktrees/$WT3/file2
assert_file_exists "$ROOT"/.worktrees/$WT3/file3
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT/.worktrees/$WT3/file3"

# wait for WT2 to go stale
sleep 2

# now both WT1 and WT2 are stale, WT3 should be the only
# worktree left
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/link/file3
assert_file_absent "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_file_absent "$ROOT"/.worktrees/$WT1/file3
assert_file_absent "$ROOT"/.worktrees/$WT2/file
assert_file_absent "$ROOT"/.worktrees/$WT2/file2
assert_file_absent "$ROOT"/.worktrees/$WT2/file3
assert_file_exists "$ROOT"/.worktrees/$WT3/file
assert_file_exists "$ROOT"/.worktrees/$WT3/file2
assert_file_exists "$ROOT"/.worktrees/$WT3/file3
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_absent "$ROOT/.worktrees/$WT2/file"
assert_file_absent "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT/.worktrees/$WT3/file3"
}

##############################################
Expand All @@ -859,9 +859,9 @@ function e2e::stale_worktree_timeout_restart() {
--link="link" \
--one-time

assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$FUNCNAME 1"
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"

# wait 2 seconds and make another commit
sleep 2
Expand All @@ -880,11 +880,11 @@ function e2e::stale_worktree_timeout_restart() {

# at this point both WT1 and WT2 should exist, with
# link pointing to the new WT2
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"

# wait 2 seconds and make a third commit
sleep 4
Expand All @@ -903,19 +903,19 @@ function e2e::stale_worktree_timeout_restart() {

# at this point WT1, WT2, WT3 should exist, with
# link pointing to WT3
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/link/file3
assert_file_exists "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_file_absent "$ROOT"/.worktrees/$WT1/file3
assert_file_exists "$ROOT"/.worktrees/$WT2/file
assert_file_exists "$ROOT"/.worktrees/$WT2/file2
assert_file_absent "$ROOT"/.worktrees/$WT2/file3
assert_file_exists "$ROOT"/.worktrees/$WT3/file
assert_file_exists "$ROOT"/.worktrees/$WT3/file2
assert_file_exists "$ROOT"/.worktrees/$WT3/file3
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/link/file3"
assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT/.worktrees/$WT3/file3"

# wait for WT1 to go stale and restart git-sync
sleep 8
Expand All @@ -928,19 +928,19 @@ function e2e::stale_worktree_timeout_restart() {

# now WT1 should be stale and deleted,
# WT2 and WT3 should still exist
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/link/file3
assert_file_absent "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_file_absent "$ROOT"/.worktrees/$WT1/file3
assert_file_exists "$ROOT"/.worktrees/$WT2/file
assert_file_exists "$ROOT"/.worktrees/$WT2/file2
assert_file_absent "$ROOT"/.worktrees/$WT2/file3
assert_file_exists "$ROOT"/.worktrees/$WT3/file
assert_file_exists "$ROOT"/.worktrees/$WT3/file2
assert_file_exists "$ROOT"/.worktrees/$WT3/file3
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT/.worktrees/$WT3/file3"

# wait for WT2 to go stale and restart git-sync
sleep 4
Expand All @@ -953,19 +953,19 @@ function e2e::stale_worktree_timeout_restart() {

# now both WT1 and WT2 are stale, WT3 should be the only
# worktree left
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/file2
assert_file_exists "$ROOT"/link/file3
assert_file_absent "$ROOT"/.worktrees/$WT1/file
assert_file_absent "$ROOT"/.worktrees/$WT1/file2
assert_file_absent "$ROOT"/.worktrees/$WT1/file3
assert_file_absent "$ROOT"/.worktrees/$WT2/file
assert_file_absent "$ROOT"/.worktrees/$WT2/file2
assert_file_absent "$ROOT"/.worktrees/$WT2/file3
assert_file_exists "$ROOT"/.worktrees/$WT3/file
assert_file_exists "$ROOT"/.worktrees/$WT3/file2
assert_file_exists "$ROOT"/.worktrees/$WT3/file3
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_absent "$ROOT/.worktrees/$WT2/file"
assert_file_absent "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT/.worktrees/$WT3/file3"
}

##############################################
Expand Down Expand Up @@ -2869,7 +2869,7 @@ function e2e::submodule_sync_relative() {

# Add submodule
REL="$(realpath --relative-to "$REPO" "$WORK/$SUBMODULE_REPO_NAME")"
echo $REL
echo "$REL"
git -C "$REPO" -c protocol.file.allow=always submodule add -q "$REL" "$SUBMODULE_REPO_NAME"
git -C "$REPO" commit -aqm "add submodule"

Expand Down Expand Up @@ -3411,7 +3411,7 @@ function list_tests() {
declare -F \
| cut -f3 -d' ' \
| grep "^e2e::" \
| while read X; do declare -F $X; done \
| while read X; do declare -F "$X"; done \
| sort -n -k2 \
| cut -f1 -d' ' \
| sed 's/^e2e:://'
Expand Down