Skip to content

Commit

Permalink
require expected-count argument to assert_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker committed Aug 3, 2017
1 parent ef9e538 commit 4a86bf1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/main/all-arg-test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ in_work_dir create_repo_from_tgz "$base_dir/files/refs-repo.tgz"

test_tig --all

assert_vars
assert_vars 1

assert_equals stderr <<EOF
EOF
Expand Down
2 changes: 1 addition & 1 deletion test/main/branch-var-test
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ in_work_dir create_repo_from_tgz "$base_dir/files/refs-repo.tgz"

test_tig --all

assert_vars
assert_vars 4

assert_equals 'main.screen' <<EOF
2009-02-13 23:31 Max Power * [mp/feature] {max-power/mp/feature} WIP
Expand Down
2 changes: 1 addition & 1 deletion test/refs/branch-var-test
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ in_work_dir create_repo_from_tgz "$base_dir/files/refs-repo.tgz"

test_tig refs

assert_vars
assert_vars 6

assert_equals 'refs.screen' <<EOF
All references
Expand Down
2 changes: 1 addition & 1 deletion test/status/repo-var-test
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ Untracked files:
[status] Nothing to update 100%
EOF

assert_vars
assert_vars 7
22 changes: 16 additions & 6 deletions test/tools/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,13 @@ assert_not_exists()
}

vars_file="vars"
expected_var_file="$HOME/expected/$vars_file"
vars_count_file="${vars_file}_assert_count"
expected_vars_file="$HOME/expected/$vars_file"

executable 'assert-var' <<EOF
#!/bin/sh
mkdir -p "$(dirname -- "$expected_var_file")"
mkdir -p "$(dirname -- "$expected_vars_file")"
lhs="\${1:-}"
if [ "\$#" -gt 0 ]; then
shift
Expand All @@ -300,15 +301,24 @@ if [ -z "\$rhs" ]; then
fi
printf '%s\\n' "\$lhs" >> "$HOME/$vars_file"
printf '%s\\n' "\$rhs" >> "$expected_var_file"
printf '%s\\n' "\$rhs" >> "$expected_vars_file"
EOF

assert_vars()
{
if [ -e "$expected_var_file" ]; then
assert_equals "$vars_file" strict "$*" < "$expected_var_file"
if [ -n "${1:-}" ]; then
printf '%s\n' "$1" > "$vars_count_file"
shift
else
die "Test must supply the expected count of assertions to assert_vars()"
fi

grep -c . "$vars_file" | assert_equals "$vars_count_file" strict "$*"

if [ -e "$expected_vars_file" ]; then
assert_equals "$vars_file" strict "$*" < "$expected_vars_file"
else
printf '[FAIL] %s not found\n' "$expected_var_file" >> .test-result
printf '[FAIL] %s not found\n' "$expected_vars_file" >> .test-result
fi
}

Expand Down

0 comments on commit 4a86bf1

Please sign in to comment.