interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / tests / nc-rd.sh

65 lines · 3563 bytes Raw Blame History
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.
11set -u
12cd "$(git rev-parse --show-toplevel)" || exit 2
13[ -x build/site ] || { echo "nc-rd: build/site is missing; build it first" >&2; exit 2; }
14RUN=${RUN:-}
15RIDS=data/public-repos.md
16OFF=public/switched-off/index.html
17T=$(mktemp -d) || exit 2
18cp "$RIDS" "$T/rids"; cp "$OFF" "$T/off"
19restore() { cp "$T/rids" "$RIDS"; cp "$T/off" "$OFF"; }
20trap 'restore; rm -rf "$T"' EXIT
21STAMP=$(git log -1 --format=%cI)
22
23# Values taken from the committed table, so the cases follow it.
24row() { grep -m1 "^| $1 | " "$T/rids"; }
25rid() { row "$1" | awk -F' [|] ' '{print $2}'; }
26MV=$(rid omega-mv)
27SITE=$(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; }
29WRONG=${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.
32add_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
34fails=0
35# case <label> <expected rc> <expected message substring or empty> <target file> <variant file or empty>
36case_() {
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
47M3="lists a PRIVATE or WITHDRAWN row"
48M4="has a malformed repo or RID cell"
49M7="not in the rdallow public list"
50M11="lists a repository name or RID more than once"
51M6="/switched-off/ source needs exactly one <!--public-repos--> marker"
52
53case_ "committed inputs" 0 "" "" ""
54add_row "$T/v" "| aienos.com | $SITE | PRIVATE |"; case_ "PRIVATE row" 70 "$M3" "$RIDS" "$T/v"
55add_row "$T/v" "| bad name! | $SITE |"; case_ "malformed name cell" 70 "$M4" "$RIDS" "$T/v"
56add_row "$T/v" "| not-listed | $SITE |"; case_ "name not in rdallow, listed RID" 70 "$M7" "$RIDS" "$T/v"
57sed "s/^| omega-mv | $MV |/| omega-mv | $WRONG |/" "$T/rids" > "$T/v"
58 case_ "listed name, wrong RID" 70 "$M7" "$RIDS" "$T/v"
59add_row "$T/v" "$(row omega-mv)"; case_ "duplicated row" 70 "$M11" "$RIDS" "$T/v"
60sed "s/<!--public-repos-->//" "$T/off" > "$T/v"; case_ "/switched-off/ without its marker" 70 "$M6" "$OFF" "$T/v"
61case_ "committed inputs, again" 0 "" "" ""
62if 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
64restore
65if [ "$fails" = 0 ]; then echo "nc-rd: all cases PASS"; else echo "nc-rd: $fails case(s) FAIL"; exit 1; fi