Files
p3dx-catkin/tests/negative.sh
T
dsh 95389f69d3 Add .gitmodules for src/rosaria, and tests that a clean clone brings code
src/rosaria and src/waypoints are gitlinks (index mode 160000) with no
.gitmodules entry, so a fresh clone created EMPTY directories. Because
src/robot/package.xml declares <depend>rosaria</depend>, a clean clone could not
be built, and the `rosrun waypoints waypoints_server` step in guide.txt could not
resolve.

- .gitmodules: declare src/rosaria -> github.com/amor-ros-pkg/rosaria.git.
  Verified rather than guessed: commit 204dc0c6785abb4037c1c5ee76439cf5f50cb880
  exists on that repository's master branch.
- src/waypoints: its origin could NOT be identified (not in the Gitea instance,
  not in the author's GitHub account, not on the machine, not on the web), so no
  entry was invented for it. It is documented in the README as a known gap and
  listed in tests/known-gaps.txt.
- tests/run.sh: offline integrity checks - packages complete, package names
  present and unique, catkin toplevel symlink, every gitlink declared or a
  documented gap, src/rosaria resolves at the pinned commit, every in-tree
  <depend> points at a package that exists. Exits non-zero on failure.
- tests/negative.sh: proves that suite has teeth by breaking one thing at a time
  in a throwaway copy, with a positive control first.
- README: where each gitlink comes from, what a clean clone still lacks, the
  darknet_ros reference in guide.txt that matches no package, and the stale
  rosaria licence row (left for the author to decide).

Known limitation, documented in the README: the untargeted
`git submodule update --init` still aborts, because the unmapped src/waypoints
gitlink has no URL to resolve. Initialise by path instead:
`git submodule update --init -- src/rosaria`. That works today and will keep
working once src/waypoints is sorted out.

No package code, CMakeLists or third-party licences were changed; the repository
stays GPL-3.0. Not proven: that the workspace builds - there is no ROS in this
environment, so catkin_make was never run.
2026-10-08 16:23:57 +01:00

111 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# tests/negative.sh - proves that tests/run.sh has teeth.
#
# Each case copies the working tree into a temporary directory, breaks exactly
# one thing THERE, and asserts that tests/run.sh then fails with the expected
# check id. Nothing in the real repository is modified: every mutation happens
# in the throwaway copy.
#
# Usage: tests/negative.sh
# Exit status: 0 = every case behaved as expected.
set -uo pipefail
ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || true
if [ -z "${ROOT:-}" ]; then
printf 'tests/negative.sh: not inside a git work tree\n' >&2
exit 2
fi
cd "$ROOT" || exit 2
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
fails=0
# --- mutations, each executed with the throwaway copy as cwd ---------------
mut_none() { :; }
# make src/rosaria an undeclared gitlink again (its .gitmodules section gone)
mut_drop_rosaria_entry() {
awk '
/^\[submodule "src\/rosaria"\]/ { skip = 1; next }
/^\[/ { skip = 0 }
!skip { print }
' .gitmodules > .gitmodules.new
mv .gitmodules.new .gitmodules
}
# no .gitmodules at all
mut_hide_gitmodules() { mv .gitmodules .gitmodules.hidden; }
# an entry that matches no gitlink
mut_add_orphan_entry() {
{
printf '\n[submodule "src/does-not-exist"]\n'
printf '\tpath = src/does-not-exist\n'
printf '\turl = https://example.invalid/does-not-exist.git\n'
} >> .gitmodules
}
# a declared package that lost a required file
mut_break_package() { mv src/robot/CMakeLists.txt src/robot/CMakeLists.txt.hidden; }
# --- runner ---------------------------------------------------------------
case_expect() {
local label=$1 expect=$2
local dir="$TMP/$label"
mkdir -p "$dir"
cp -a "$ROOT/." "$dir/"
( cd "$dir" && "$label" )
local out rc
out=$(cd "$dir" && tests/run.sh 2>&1)
rc=$?
printf -- '--- %s ---\n' "$label"
if [ "$expect" = "PASS" ]; then
if [ "$rc" -eq 0 ]; then
printf ' PASS run.sh exited 0 as expected\n'
else
printf ' FAIL run.sh exited %s, expected 0\n' "$rc"
printf '%s\n' "$out" | sed 's/^/ /'
fails=$((fails + 1))
fi
return 0
fi
if [ "$rc" -eq 0 ]; then
printf ' FAIL run.sh exited 0, but [%s] was expected to fail\n' "$expect"
fails=$((fails + 1))
elif printf '%s\n' "$out" | grep -q "FAIL \[$expect\]"; then
printf ' PASS run.sh failed with [%s] (exit %s)\n' "$expect" "$rc"
else
printf ' FAIL run.sh failed, but without the expected id [%s]\n' "$expect"
printf '%s\n' "$out" | sed 's/^/ /'
fails=$((fails + 1))
fi
return 0
}
echo "== negative tests for tests/run.sh =="
echo
# The positive control runs first: on an untouched copy the suite must be green,
# so any failure below really is caused by the mutation and not by a broken suite.
case_expect mut_none PASS
case_expect mut_drop_rosaria_entry gitlink-undeclared
case_expect mut_hide_gitmodules gitmodules-missing
case_expect mut_add_orphan_entry gitmodules-orphan
case_expect mut_break_package cmakelists-missing
echo
if [ "$fails" -eq 0 ]; then
echo "ALL NEGATIVE CASES BEHAVED AS EXPECTED"
exit 0
fi
printf '%s negative case(s) did not behave as expected\n' "$fails"
exit 1