run_errors.sh (2748B)
1 #!/usr/bin/env bash 2 # test/pp/run_errors.sh — data-driven preprocessor must-fail runner, on the 3 # shared corpus harness (test/lib/kit_corpus.sh). Single negative lane. 4 # 5 # For each test/pp/cases_err/*.c, runs `kit cc -E` and expects a nonzero exit 6 # (constraint violations from C11 §6.10 must be diagnosed). The oracle checks 7 # exit status only; stderr is captured under $KIT_WORK but not pattern-matched 8 # (these cases ship no diagnostic sidecar). Kept as a separate runner from the 9 # positive pp golden-diff runner (test-pp vs test-pp-err). 10 # 11 # Like run.sh, exports SOURCE_DATE_EPOCH=0 and cd's into the cases dir so 12 # __DATE__/__TIME__/__FILE__ are deterministic. 13 # 14 # No opt axis. Honors $KIT for the binary path; defaults to build/kit. 15 # 16 # Filtering: ./run_errors.sh [name_filter] (or KIT_TEST_FILTER); substring 17 # match against case basename. 18 # 19 # Parallelism: parallel by default; KIT_TEST_JOBS=N caps concurrency; 20 # KIT_PP_PARALLEL=0 forces serial. The lane hook keeps all output under 21 # $KIT_WORK, so the summary is identical serial or parallel. 22 23 set -u 24 25 script_dir=$(cd "$(dirname "$0")" && pwd) 26 repo_root=$(cd "$script_dir/../.." && pwd) 27 cases_dir="$script_dir/cases_err" 28 29 export KIT_LIB_DIR="$repo_root/test/lib" 30 # shellcheck source=../lib/kit_corpus.sh 31 . "$repo_root/test/lib/kit_corpus.sh" 32 33 KIT="${KIT:-$repo_root/build/kit}" 34 35 if [ ! -x "$KIT" ]; then 36 echo "pp-err: kit binary not found at $KIT" >&2 37 exit 2 38 fi 39 40 # Match run.sh so __DATE__/__TIME__/__FILE__ are deterministic. 41 export SOURCE_DATE_EPOCH=0 42 43 # cd into the cases dir so the corpus glob yields bare basenames (deterministic 44 # __FILE__) and -I . resolves sibling headers. 45 cd "$cases_dir" || exit 2 46 47 BUILD_DIR="$repo_root/build/test/pp" 48 mkdir -p "$BUILD_DIR" 49 50 FILTER="${1:-${KIT_TEST_FILTER:-}}" 51 export KIT_TEST_FILTER="$FILTER" 52 53 # ----- negative lane P: cc -E must fail (exit status only) ------------------- 54 # KIT_SRC is a bare basename (cwd == cases dir). Output goes to /dev/null per the 55 # original (the preprocessed text is irrelevant); stderr/stdout logs stay under 56 # $KIT_WORK for parallel safety. 57 kit_lane_P() { 58 local name="$KIT_BASE" 59 if "$KIT" cc -E -I . "$KIT_SRC" -o /dev/null \ 60 >"$KIT_WORK/pp.out" 2>"$KIT_WORK/pp.err"; then 61 kit_fail "$name" "expected nonzero exit, got success" 62 else 63 kit_pass "$name" 64 fi 65 } 66 67 # ----- drive the corpus ----------------------------------------------------- 68 69 PAR="${KIT_PP_PARALLEL:-1}" 70 71 KIT_LABEL=test-pp-err KIT_BUILD_DIR="$BUILD_DIR/cases_err" \ 72 KIT_CORPUS_GLOBS="*.c" KIT_CORPUS_EXT=c KIT_SIDECAR_DIR="$cases_dir" \ 73 KIT_LANES="P" KIT_OPT_LEVELS="" KIT_TUPLES="none-none" KIT_TARGETS_EXT="" \ 74 KIT_PARALLELIZABLE="$PAR" kit_corpus_run 75 76 kit_summary test-pp-err 77 kit_exit