diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/libyaml-emitter.t | 36 | ||||
-rw-r--r-- | test/libyaml-parser-error.t | 28 | ||||
-rw-r--r-- | test/libyaml-parser.t | 33 | ||||
-rw-r--r-- | test/test-runner.bash | 35 |
4 files changed, 132 insertions, 0 deletions
diff --git a/test/libyaml-emitter.t b/test/libyaml-emitter.t new file mode 100644 index 0000000..3f3d8be --- /dev/null +++ b/test/libyaml-emitter.t @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# shellcheck disable=1090,2034 + +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + +source "$root"/test/test-runner.bash + +check-test() { + id=$1 + t=data/$id + + grep "$id" "$root/blacklist/libyaml-emitter" >/dev/null && return 1 + [[ -e $t/error ]] && return 1 + + return 0 +} + +run-test() { + dir=$1 + ok=true + + want=$dir/out.yaml + [[ -e $want ]] || want="$dir/in.yaml" + + libyaml/tests/run-emitter-test-suite "$dir/test.event" > /tmp/test.out || { + ( + cat "$dir/test.event" + cat "$want" + ) | sed 's/^/# /' + } + + output="$(${DIFF:-diff} -u "$want" /tmp/test.out)" || ok=false +} + +run-tests "$@" diff --git a/test/libyaml-parser-error.t b/test/libyaml-parser-error.t new file mode 100644 index 0000000..a51578e --- /dev/null +++ b/test/libyaml-parser-error.t @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# shellcheck disable=1090,2034 + +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + +source "$root"/test/test-runner.bash + +check-test() { + id=$1 + t=data/$id + + grep "$id" "$root/blacklist/libyaml-parser-error" >/dev/null && return 1 + [[ -e $t/error ]] || return 1 + + return 0 +} + +run-test() { + dir=$1 + ok=false + + libyaml/tests/run-parser-test-suite "$dir/in.yaml" > /tmp/test.out 2>&1 || ok=true + + $ok || output=$(< /tmp/test.out) +} + +run-tests "$@" diff --git a/test/libyaml-parser.t b/test/libyaml-parser.t new file mode 100644 index 0000000..5e9cb94 --- /dev/null +++ b/test/libyaml-parser.t @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# shellcheck disable=1090,2034 + +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + +source "$root"/test/test-runner.bash + +check-test() { + id=$1 + t=data/$id + + grep "$id" "$root/blacklist/libyaml-parser" >/dev/null && return 1 + [[ -e $t/error ]] && return 1 + + return 0 +} + +run-test() { + dir=$1 + ok=true + + libyaml/tests/run-parser-test-suite "$dir/in.yaml" > /tmp/test.out || { + ( + cat "$dir/in.yaml" + cat "$dir/test.event" + ) | sed 's/^/# /' + } + + output=$(${DIFF:-diff} -u "$dir/test.event" /tmp/test.out) || ok=false +} + +run-tests "$@" diff --git a/test/test-runner.bash b/test/test-runner.bash new file mode 100644 index 0000000..8360308 --- /dev/null +++ b/test/test-runner.bash @@ -0,0 +1,35 @@ +# shellcheck disable=2001,2154,2207 + +set -e -u -o pipefail + +run-tests() ( + root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + + cd "$root" + + if [[ $# -gt 0 ]]; then + ids=("$@") + else + ids=($(cd data; printf "%s\n" * | grep '[0-9]')) + fi + + count=0 + for id in "${ids[@]}"; do + check-test "$id" || continue + + 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" +) |