blob: 5ffc55c0856abf336ff53ee8047683a03cdc2320 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
#!/usr/bin/env bats
# tests/integration/cli.bats
# Tests for trbldoc.sh command-line option parsing.
#
# Each test runs the full script (with md2html stubs) and asserts that
# the correct sources are scanned and outputs produced, based on the options
# passed.
load "../helpers/common.bash"
load "../helpers/profiler.bash"
FIXTURES="$BATS_TEST_DIRNAME/../fixtures"
_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 ──────────────────────────────────────────────────────────────────
run_pipeline() {
bash "$TRBLDOC" "$@" # 2>/dev/null
#profile "$TRBLDOC" "$@" 2>/dev/null
#analyze >> profile.txt
}
stage_fixture() {
local src="$1"
local dest="$2"
mkdir -p "$(dirname "$dest")"
cp -r "$src" "$dest"
}
# ── error cases ──────────────────────────────────────────────────────────────
@test "cli: no arguments exits non-zero with an error message" {
run bash "$TRBLDOC" 2>&1
[ "$status" -ne 0 ]
[[ "$output" == *"trbldoc:"* ]]
}
@test "cli: unknown option exits non-zero" {
run bash "$TRBLDOC" -z 2>&1
[ "$status" -ne 0 ]
}
@test "cli: option missing its required argument exits non-zero" {
run bash "$TRBLDOC" -s 2>&1
[ "$status" -ne 0 ]
}
# ── -s (source folder) ───────────────────────────────────────────────────────
@test "cli: -s flag specifies the source folder to scan" {
stage_fixture "$FIXTURES/c/simple.c" "src/simple.c"
run_pipeline -s src
assert_dir_exists "$NS/test/simple"
}
@test "cli: multiple -s flags scan all specified folders" {
stage_fixture "$FIXTURES/c/simple.c" "src1/simple.c"
stage_fixture "$FIXTURES/c/multi_chunk.c" "src2/multi_chunk.c"
run_pipeline -s src1 -s src2
assert_dir_exists "$NS/test/simple"
assert_dir_exists "$NS/test/alpha"
}
# ── -o (output directory) ────────────────────────────────────────────────────
@test "cli: -o flag creates the specified output directory" {
stage_fixture "$FIXTURES/c/simple.c" "src/simple.c"
run_pipeline -s src -o my_output
assert_dir_exists "my_output"
assert_file_exists "my_output/test/simple/index.html"
}
@test "cli: without -o the default output directory .trblcache/built is created" {
stage_fixture "$FIXTURES/c/simple.c" "src/simple.c"
run_pipeline -s src
assert_dir_exists "$CACHE/built"
}
# ── -f (custom file extension) ───────────────────────────────────────────────
@test "cli: -f flag registers a custom file extension for scanning" {
mkdir -p src
# Create a .myext file with C-style doc comments.
# The -f option takes ext;start_regex;end_regex (AWK patterns without slashes).
cat > src/custom.myext <<'SRCEOF'
/* md
@name test/custom-ext
Hello from a custom extension.
*/
int noop() {}
SRCEOF
run_pipeline -s src -f 'myext;\/\*;\*\/'
assert_dir_exists "$NS/test/custom-ext"
}
@test "cli: -f registered extension produces correct chunk content" {
mkdir -p src
cat > src/custom.myext <<'SRCEOF'
/* md
@name test/custom-content
Content from custom ext.
*/
int noop() {}
SRCEOF
run_pipeline -s src -f 'myext;\/\*;\*\/'
assert_contains "$NS/test/custom-content/index.html" "Content from custom ext"
}
# ── TRBLDOC_MD (markdown renderer override) ──────────────────────────────────
@test "cli: TRBLDOC_MD overrides the markdown renderer for .md files" {
mkdir -p src
cat > src/doc.md <<'EOF'
@name test/md-override
# Heading
Some content.
EOF
cat > custom_md.sh <<'EOF'
#!/usr/bin/env bash
# Stub: emit a recognisable marker instead of real HTML.
cat "$@" > /dev/null
echo "<p class=\"custom-md-renderer\">custom renderer was here</p>"
EOF
chmod +x custom_md.sh
TRBLDOC_MD="./custom_md.sh" run_pipeline -s src
assert_contains "$NS/test/md-override/index.html" "custom-md-renderer"
}
@test "cli: TRBLDOC_MD override is not used when unset (default md2html stub runs)" {
stage_fixture "$FIXTURES/md/simple.md" "src/simple.md"
run_pipeline -s src
# The default stub wraps content in class=stub-md; confirm it ran.
assert_contains "$NS/test/md-simple/index.html" "stub-md"
}
# ── built-in site assembly ───────────────────────────────────────────────────
@test "cli: built output is assembled by default without external zod" {
mkdir -p src
cat > src/simple.c <<'EOF'
/* md
@name test/simple
Hello from a C comment.
*/
int main() { return 0; }
EOF
run_pipeline -s src
assert_file_exists "$CACHE/built/test/simple/index.html"
assert_contains "$CACHE/built/test/simple/index.html" "<!DOCTYPE html>"
assert_contains "$CACHE/built/test/simple/index.html" "Hello from a C comment"
assert_not_contains "$CACHE/built/test/simple/index.html" "{{{yield}}}"
}
@test "cli: default main.layout includes stylesheet and excludes highlightjs mermaid and mathjax" {
stage_fixture "$FIXTURES/c/simple.c" "src/simple.c"
run_pipeline -s src
assert_contains "$NS/main.layout" '<link href="/stylesheets/style.css" rel="stylesheet">'
assert_not_contains "$NS/main.layout" "highlight.min.js"
assert_not_contains "$NS/main.layout" "highlightAll()"
assert_not_contains "$NS/main.layout" "mermaid.min.js"
assert_not_contains "$NS/main.layout" "mermaid.initialize"
assert_not_contains "$NS/main.layout" "mathjax"
}
@test "cli: -l uses the provided main.layout template" {
stage_fixture "$FIXTURES/c/simple.c" "src/simple.c"
cat > alt.layout <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>{{ title }}</title></head>
<body>
<header>ALT {{ breadcrumb }}</header>
<nav><ul>{{ nav }}</ul></nav>
<main>{{ yield }}</main>
</body>
</html>
EOF
run_pipeline -s src -l alt.layout
assert_contains "$NS/main.layout" "ALT {{ breadcrumb }}"
assert_not_contains "$NS/main.layout" "Generated by trbldoc"
}
@test "cli: -l fails when layout template file does not exist" {
stage_fixture "$FIXTURES/c/simple.c" "src/simple.c"
run bash "$TRBLDOC" -s src -l does-not-exist.layout 2>&1
[ "$status" -ne 0 ]
[[ "$output" == *"layout template not found"* ]]
}
@test "cli: files without a registered extension are not scanned" {
mkdir -p src
# .xyz has no registered comment form; no output namespace should appear.
cat > src/ignored.xyz <<'SRCEOF'
/* md
@name test/should-not-exist
This should not be processed.
*/
SRCEOF
run_pipeline -s src
if [[ -d "$NS/test/should-not-exist" ]]; then
echo "FAILED: .xyz file was unexpectedly processed" >&2
return 1
fi
}
|