File: testsuite-json.test

package info (click to toggle)
libfyaml 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,328 kB
  • sloc: ansic: 62,193; asm: 8,692; sh: 1,628; makefile: 581; python: 23
file content (91 lines) | stat: -rwxr-xr-x 2,104 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash

count=0
for basetst in test-suite-data/[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]/; do
	for tst in ${basetst} ${basetst}[0-9][0-9]/ ${basetst}[0-9][0-9][0-9]/; do
		# there must be a test there
		if [ ! -e "$tst/===" ]; then
			continue
		fi
		# ignore tests which are expected to fail
		if [ -e "$tst/error" ]; then
			continue
		fi
		# a json file must be there
		if [ ! -e "$tst/in.json" ]; then
			continue
		fi
		count=`expr $count + 1`
	done
done

# output plan
echo 1..$count

declare -A skips=(
	[UGM3]="Later jq versions rewrite numbers like 12.00 -> 12 which breaks diff"
)
declare -A xfails=(
	[C4HZ]="requires schema support which libfyaml does not support yet."
)

i=0
for basetst in test-suite-data/[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]/; do

	for tst in ${basetst} ${basetst}[0-9][0-9]/ ${basetst}[0-9][0-9][0-9]/; do

		# ignore tests which are expected to fail
		if [ -e "$tst/error" ]; then
			continue
		fi
		# a json file must be there
		if [ ! -e "$tst/in.json" ]; then
			continue
		fi

		i=`expr $i + 1`

		# strip trailing /
		t=${tst%/}
		# remove test-suite-data/
		test_subtest_id=`echo $t | cut -d/ -f2-`
		test_id=`echo $test_subtest_id | cut -d/ -f1`
		subtest_id=`echo $test_subtest_id | cut -s -d/ -f2`

		desctxt=`cat 2>/dev/null "$tst/==="`

		directive=""
		skip_reason="${skips[$test_subtest_id]}"
		if [ "x$skip_reason" != "x" ]; then
			directive=" # SKIP: ${skip_reason}"
		fi

		res="ok"
		if [ "x$skip_reason" == "x" ]; then
			t1=`mktemp`
			t2=`mktemp`

			# output yaml in json format
			${TOP_BUILDDIR}/src/fy-tool --dump --strip-labels --strip-tags --strip-doc -r -mjson "$tst/in.yaml" | "${JQ}" --sort-keys . >"$t1"

			# do the same with the json input (canonicalize)
			cat "$tst/in.json" | "${JQ}" --sort-keys . > "$t2"

			diff -u "$t1" "$t2"
			if [ $? -eq 0 ]; then
				res="ok"
			else
				res="not ok"
			fi

			rm -f "$t1" "$t2"

			xfail_reason="${xfails[$test_subtest_id]}"
			if [ "x$xfail_reason" != "x" ]; then
				directive=" # TODO: ${xfail_reason}"
			fi
		fi

		echo "$res $i $test_subtest_id - $desctxt (JSON)$directive"
	done
done