aurutils: v18.4
[aurutils.git] / tests / format
blob01fdb73b27fa665b5b643de6aa8fc79b0b12d9b9
1 #!/bin/bash
2 set -e
3 tests_t=(json/{ascii,depends,meta,none,empty_a,search,utf-8}.json*)
4 tests_f=(json/{empty,error}.json)
6 for t in "${tests_t[@]}"; do
7 # check if correct amount of entries were parsed
8 cnt1=$(aur format -f '%n\n' "$t" | wc -l)
10 # variable input formats
11 u=${t%%.json}
12 case ${u##json/} in
13 ascii|depends|search|utf-8|none)
14 cnt2=$(jq < "$t" '.results | length') ;;
15 meta|empty_a)
16 cnt2=$(jq < "$t" '. | length') ;;
17 search.jsonl)
18 cnt2=$(jq < "$t" -s 'map(.results | length) | add') ;;
19 esac
20 [[ $cnt1 == "$cnt2" ]]
21 done
23 # error codes:
24 # 1: option error
25 # 2: file error
26 # 4: invalid input
28 # exit on invalid potion
29 aur format json/ascii.json --doesnotexit || err=$?
30 [[ $err == 1 ]]
31 aur format json/ascii.json || err=$?
32 [[ $err == 1 ]]
34 # exit >0 if file path does not exist
35 aur format -f '%n' /does/not/exist || err=$?
36 [[ $err == 2 ]]
38 # check for errors on invalid inputs
39 aur format -f '%n' json/error.json || err=$? # response error
40 [[ $err == 4 ]]
42 # check modes with empty stdin
43 printf '' | aur format -f '%n\n'