aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / tests / nc-rd.sh
| 1 | #!/bin/bash |
| 2 | # Negative controls for om/site/repos.om (the public repository table behind /switched-off/, |
| 3 | # which shows names only). Each case puts one bad input in place of a committed file, runs |
| 4 | # the generator, expects rc 70 with the named message, and restores the file. |
| 5 | # |
| 6 | # Run from the repository root after the build has made build/site: |
| 7 | # om/site/omc < om/site/build.om > build/build-tool && chmod +x build/build-tool |
| 8 | # build/build-tool om/site/modules.txt build/site |
| 9 | # tests/nc-rd.sh # RUN="taskset -c 2 nice -n 10" tests/nc-rd.sh to pin a core |
| 10 | # Exit status 0 only when every case gives the expected result. |
| 11 | set -u |
| 12 | cd "$(git rev-parse --show-toplevel)" || exit 2 |
| 13 | [ -x build/site ] || { echo "nc-rd: build/site is missing; build it first" >&2; exit 2; } |
| 14 | RUN=${RUN:-} |
| 15 | RIDS=data/public-repos.md |
| 16 | OFF=public/switched-off/index.html |
| 17 | T=$(mktemp -d) || exit 2 |
| 18 | cp "$RIDS" "$T/rids"; cp "$OFF" "$T/off" |
| 19 | restore() { cp "$T/rids" "$RIDS"; cp "$T/off" "$OFF"; } |
| 20 | trap 'restore; rm -rf "$T"' EXIT |
| 21 | STAMP=$(git log -1 --format=%cI) |
| 22 | |
| 23 | # Values taken from the committed table, so the cases follow it. |
| 24 | row() { grep -m1 "^| $1 | " "$T/rids"; } |
| 25 | rid() { row "$1" | awk -F' [|] ' '{print $2}'; } |
| 26 | MV=$(rid omega-mv) |
| 27 | SITE=$(rid aienos.com) |
| 28 | [ -n "$MV" ] && [ -n "$SITE" ] && [ -n "$(rid cuda-crack)" ] || { echo "nc-rd: committed table lacks omega-mv, aienos.com or cuda-crack" >&2; exit 2; } |
| 29 | WRONG=${MV%?}$([ "${MV: -1}" = X ] && echo Y || echo X) |
| 30 | |
| 31 | # add_row <file> <line>: the committed table with one row added after its last row. |
| 32 | add_row() { awk -v r="$2" '{ if (in_t && $0 !~ /^\|/) { print r; in_t = 0; done = 1 } print; if ($0 ~ /^\|---/ && !done) in_t = 1 } END { if (in_t && !done) print r }' "$T/rids" > "$1"; } |
| 33 | |
| 34 | fails=0 |
| 35 | # case <label> <expected rc> <expected message substring or empty> <target file> <variant file or empty> |
| 36 | case_() { |
| 37 | restore |
| 38 | [ -n "$5" ] && cp "$5" "$4" |
| 39 | rm -rf "$T/dist" |
| 40 | $RUN build/site "$PWD" "$T/dist" "$STAMP" > "$T/out" 2>&1 |
| 41 | rc=$? |
| 42 | msg=$(grep -a "site runtime" "$T/out" | tail -1) |
| 43 | if [ "$rc" = "$2" ] && { [ -z "$3" ] || [[ "$msg" == *"$3"* ]]; }; then r=PASS; else r=FAIL; fails=$((fails + 1)); fi |
| 44 | echo "$r $1: rc=$rc ${msg:-}" |
| 45 | } |
| 46 | |
| 47 | M3="lists a PRIVATE or WITHDRAWN row" |
| 48 | M4="has a malformed repo or RID cell" |
| 49 | M7="not in the rdallow public list" |
| 50 | M11="lists a repository name or RID more than once" |
| 51 | M6="/switched-off/ source needs exactly one <!--public-repos--> marker" |
| 52 | |
| 53 | case_ "committed inputs" 0 "" "" "" |
| 54 | add_row "$T/v" "| aienos.com | $SITE | PRIVATE |"; case_ "PRIVATE row" 70 "$M3" "$RIDS" "$T/v" |
| 55 | add_row "$T/v" "| bad name! | $SITE |"; case_ "malformed name cell" 70 "$M4" "$RIDS" "$T/v" |
| 56 | add_row "$T/v" "| not-listed | $SITE |"; case_ "name not in rdallow, listed RID" 70 "$M7" "$RIDS" "$T/v" |
| 57 | sed "s/^| omega-mv | $MV |/| omega-mv | $WRONG |/" "$T/rids" > "$T/v" |
| 58 | case_ "listed name, wrong RID" 70 "$M7" "$RIDS" "$T/v" |
| 59 | add_row "$T/v" "$(row omega-mv)"; case_ "duplicated row" 70 "$M11" "$RIDS" "$T/v" |
| 60 | sed "s/<!--public-repos-->//" "$T/off" > "$T/v"; case_ "/switched-off/ without its marker" 70 "$M6" "$OFF" "$T/v" |
| 61 | case_ "committed inputs, again" 0 "" "" "" |
| 62 | if grep -qE 'rad:z|rad clone' "$T/dist/switched-off/index.html"; then echo "FAIL /switched-off/ shows a Radicle ID or clone command"; fails=$((fails + 1)); else echo "PASS /switched-off/ shows names only"; fi |
| 63 | |
| 64 | restore |
| 65 | if [ "$fails" = 0 ]; then echo "nc-rd: all cases PASS"; else echo "nc-rd: $fails case(s) FAIL"; exit 1; fi |