Skip to content

Commit

Permalink
Merge pull request #712 from rolandwalker/assert-vars-followup
Browse files Browse the repository at this point in the history
require expected-asserts count argument to assert_vars
  • Loading branch information
jonas committed Aug 3, 2017
2 parents 0be21e1 + 4a86bf1 commit 998d8f3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 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
24 changes: 17 additions & 7 deletions test/tools/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ ORIG_IFS=
assert_equals()
{
file="$1"; shift
whitespace_arg="ignore";
whitespace_arg='-w';

if [ "$#" -ge 1 ]; then
whitespace_arg="${1:-}"
Expand Down 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 "message" < "$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 998d8f3

Please sign in to comment.