#!/usr/bin/env bats # tests/integration/pipeline.bats # End-to-end tests for trbldoc.sh. # # External markdown rendering is stubbed via helpers/common.bash. # Tests inspect both .trblcache/namespace intermediate output and the assembled # .trblcache/built pages produced by trbldoc itself. # # Tests marked `skip` document known bugs from todo.md. Remove `skip` after # the corresponding bug is fixed. load "../helpers/common.bash" FIXTURES="$BATS_TEST_DIRNAME/../fixtures" # REPO_ROOT is exported by run_tests.sh; fall back to relative path when bats # is invoked directly on this file. _REPO_ROOT="${REPO_ROOT:-$(cd "$BATS_TEST_DIRNAME/../.." && pwd)}" TRBLDOC="$_REPO_ROOT/trbldoc.sh" setup() { setup_workspace CACHE=".trblcache" NS="$CACHE/namespace" } teardown() { teardown_workspace } # ── helpers ───────────────────────────────────────────────────────────────── # Copy a fixture file into a temporary source tree and run the pipeline. # Usage: run_pipeline SRC_DIR [additional source dirs...] run_pipeline() { bash "$TRBLDOC" "$@" } # Copy a fixture into a local source dir for a clean run. stage_fixture() { local src="$1" # path to fixture file or dir local dest="$2" # destination relative path in tmp workspace mkdir -p "$(dirname "$dest")" cp -r "$src" "$dest" } install_busybox_tool_wrapper() { local tool="$1" local busybox_bin="$2" cat > "$STUB_BIN/$tool" <> "\$TRBLDOC_TEST_TOOL_LOG" fi exec "$busybox_bin" $tool "\$@" EOF chmod +x "$STUB_BIN/$tool" } # ── cache structure ────────────────────────────────────────────────────────── @test "pipeline: .trblcache directory is created on run" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src assert_dir_exists ".trblcache" } @test "pipeline: namespace subdirectory is created on run" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src assert_dir_exists ".trblcache/namespace" } @test "pipeline: chunks subdirectory is created on run" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src assert_dir_exists ".trblcache/chunks" } @test "pipeline: global.meta is created" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src assert_file_exists "$NS/global.meta" } @test "pipeline: main.layout is created" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src assert_file_exists "$NS/main.layout" } @test "pipeline: main.layout passes HTML validation" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src assert_valid_html "$NS/main.layout" } @test "pipeline: main.layout has well-formed HTML structure" { stage_fixture "$FIXTURES/c/simple.c" "src/simple.c" run_pipeline -s src local layout="$NS/main.layout" # must appear before local html_line head_line body_line footer_line close_body_line html_line=$(grep -n '' "$layout" | head -1 | cut -d: -f1) # before [ "$html_line" -lt "$head_line" ] # exactly one local head_count head_count=$(grep -c '' "$layout") assert_equal "$head_count" "1" #