build, chroot: don't quote for non-interactive usage
[aurutils.git] / tests / repo-parse
blob6b37c0f2552190b1148e34c16bfe319516706053
1 #!/bin/bash
2 set -e
3 core_path=/var/lib/pacman/sync/core.db
4 core_files_path=/var/lib/pacman/sync/core.files
6 # check repository entries are parsed correctly
7 diff -u <(pacsift --repo=core | expac -S '%n\t%v' - | sort -u) \
8 <(aur repo-parse -p "$core_path" --list | sort -u)
10 # check attributes are up-to-date
11 cnt1=$({ echo GROUPS; bsdtar -Oxf "$core_files_path" | grep -Po '(?<=%).+(?=%)'; } | sort -u | wc -l) \
12 cnt2=$(aur repo-parse --list-attr | wc -l)
13 (( cnt1 == cnt2 ))
15 # check if output is valid JSON
16 aur repo-parse -p "$core_files_path" --json | tee core.json | jq -e >/dev/null
18 # check if fields match aur-format
19 diff -u <(aur format -F '%n\t%v\n' core.json) \
20 <(aur repo-parse -p "$core_files_path" --list)
22 # test formatting options applicable to pacman repositories
23 fmt_p=('f' 'F' 'r')
24 fmt_c=('a' 'b' 'c' 'C' 'd' 'D' 'e' 'g' 'M' 'n' 'O' 'P' 'U' 'v')
26 for f in "${fmt_p[@]}" "${fmt_c[@]}"; do
27 cnt=$(aur format core.json --format "$f\n" | awk NF | wc -l)
28 (( cnt > 0 ))
29 done
31 # option checks
32 aur repo-parse || err=$?
33 [[ $err == 1 ]]
34 aur repo-parse -p /does/not/exist --list || err=$?
35 [[ $err == 2 ]]
37 # --json output with varying number of packages
38 core_entries=('acl-*/desc' 'archlinux-keyring-*/desc')
39 json_cnt1=$(bsdtar -Oxf "$core_path" "${core_entries[0]}" | aur repo-parse --json - | jq '. | length')
40 [[ $json_cnt1 == 1 ]]
41 json_cnt2=$(bsdtar -Oxf "$core_path" "${core_entries[@]:0:2}" | aur repo-parse --json - | jq '. | length')
42 [[ $json_cnt2 == 2 ]]
43 json_cnt3=$(printf '\n' | aur repo-parse --json - | jq '. | length')
44 [[ -z $json_cnt3 ]]
46 # --json output with constrained entries
47 aur repo-parse -p "$core_files_path" --json -s '^a' | jq '. | length' >/dev/null