diff options
author | Ingy döt Net <ingy@ingy.net> | 2019-12-21 12:50:54 -0800 |
---|---|---|
committer | Ingy döt Net <ingy@ingy.net> | 2019-12-21 12:50:54 -0800 |
commit | a865a536bcd0c5b1713b9939ed923ea08879e16a (patch) | |
tree | 367cd80cea7ff0c8d7aa7c3189f8f4c5e61d886b | |
parent | 54cbd238b18823d02058cf9814124b1784566d9e (diff) | |
download | libyaml-git-a865a536bcd0c5b1713b9939ed923ea08879e16a.tar.gz |
Refactor testing scripts
-rwxr-xr-x | libyaml-emitter.t | 33 | ||||
-rwxr-xr-x | libyaml-parser-error.t | 32 | ||||
-rwxr-xr-x | libyaml-parser.t | 31 | ||||
-rw-r--r-- | test-runner.bash | 29 |
4 files changed, 61 insertions, 64 deletions
diff --git a/libyaml-emitter.t b/libyaml-emitter.t index a8ec7bf..d62a8bd 100755 --- a/libyaml-emitter.t +++ b/libyaml-emitter.t @@ -1,19 +1,15 @@ #!/usr/bin/env bash -set -e +# shellcheck disable=1090,2034 -if [[ $# -gt 0 ]]; then - ids=("$@") -else - ids=($(cut -d: -f1 < test/list/libyaml-emitter.list)) -fi +root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -count=0 -for id in "${ids[@]}"; do - dir="data/$id" - label="$id: $(< $dir/===)" - [[ -e "$dir/in.yaml" ]] || continue - want="$dir/out.yaml" +source "$root"/test-runner.bash + +run-test() { + dir=$1 + ok=true + want=$dir/out.yaml [[ -e $want ]] || want="$dir/in.yaml" ../../tests/run-emitter-test-suite "$dir/test.event" > /tmp/test.out || { ( @@ -21,14 +17,7 @@ for id in "${ids[@]}"; do cat "$want" ) | sed 's/^/# /' } - ok=true - output="$(${DIFF:-diff} -u $want /tmp/test.out)" || ok=false - if $ok; then - echo "ok $((++count)) $label" - else - echo "not ok $((++count)) $label" - echo "$output" | sed 's/^/# /' - fi -done + output="$(${DIFF:-diff} -u "$want" /tmp/test.out)" || ok=false +} -echo "1..$count" +run-tests "$root/list/libyaml-emitter.list" "$@" diff --git a/libyaml-parser-error.t b/libyaml-parser-error.t index d9613de..7e444c8 100755 --- a/libyaml-parser-error.t +++ b/libyaml-parser-error.t @@ -1,26 +1,16 @@ #!/usr/bin/env bash -set -e +# shellcheck disable=1090,2034 -if [[ $# -gt 0 ]]; then - ids=("$@") -else - ids=($(cut -d: -f1 < test/list/libyaml-parser-error.list)) -fi +root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -count=0 -for id in "${ids[@]}"; do - dir="data/$id" - label="$id: $(< $dir/===)" - [[ -e "$dir/in.yaml" ]] || continue - ok=true - ../../tests/run-parser-test-suite "$dir/in.yaml" > /tmp/test.out 2>&1 || ok=false - if $ok; then - echo "not ok $((++count)) $label" - sed 's/^/# /' /tmp/test.out - else - echo "ok $((++count)) $label" - fi -done +source "$root"/test-runner.bash -echo "1..$count" +run-test() { + dir=$1 + ok=false + ../../tests/run-parser-test-suite "$dir/in.yaml" > /tmp/test.out 2>&1 || ok=true + $ok || output=$(< /tmp/test.out) +} + +run-tests "$root/list/libyaml-parser-error.list" "$@" diff --git a/libyaml-parser.t b/libyaml-parser.t index 0f2afd7..f3ef67f 100755 --- a/libyaml-parser.t +++ b/libyaml-parser.t @@ -1,32 +1,21 @@ #!/usr/bin/env bash -set -e +# shellcheck disable=1090,2034 -if [[ $# -gt 0 ]]; then - ids=("$@") -else - ids=($(cut -d: -f1 < test/list/libyaml-parser.list)) -fi +root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -count=0 -for id in "${ids[@]}"; do - dir="data/$id" - label="$id: $(< $dir/===)" - [[ -e "$dir/in.yaml" ]] || continue +source "$root"/test-runner.bash + +run-test() { + dir=$1 + ok=true ../../tests/run-parser-test-suite "$dir/in.yaml" > /tmp/test.out || { ( cat "$dir/in.yaml" cat "$dir/test.event" ) | sed 's/^/# /' } - ok=true - output="$(${DIFF:-diff} -u $dir/test.event /tmp/test.out)" || ok=false - if $ok; then - echo "ok $((++count)) $label" - else - echo "not ok $((++count)) $label" - echo "$output" | sed 's/^/# /' - fi -done + output=$(${DIFF:-diff} -u "$dir/test.event" /tmp/test.out) || ok=false +} -echo "1..$count" +run-tests "$root/list/libyaml-parser.list" "$@" diff --git a/test-runner.bash b/test-runner.bash new file mode 100644 index 0000000..623a564 --- /dev/null +++ b/test-runner.bash @@ -0,0 +1,29 @@ +# shellcheck disable=2001,2154,2207 + +run-tests() { + whitelist_file=$1; shift + + if [[ $# -gt 0 ]]; then + ids=("$@") + else + ids=($(cut -d: -f1 < "$whitelist_file")) + fi + + count=0 + for id in "${ids[@]}"; do + dir=data/$id + label="$id: $(< "$dir/===")" + [[ -e $dir/in.yaml ]] || continue + + run-test "$dir" + + if $ok; then + echo "ok $((++count)) $label" + else + echo "not ok $((++count)) $label" + echo "$output" | sed 's/^/# /' + fi + done + + echo "1..$count" +} |