Skip to content

Commit f3d8362

Browse files
olehermanseclaude
andcommitted
Added new testing framework for linting tests
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
1 parent f7df415 commit f3d8362

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

tests/lint/001_hello_world.cf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bundle agent main
2+
{
3+
reports:
4+
"Hello, world!";
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
"Hello, CFEngine"
3+
ifvarclass => "cfengine";
4+
^--------^
5+
Deprecation: Use 'if' instead of 'ifvarclass' at tests/lint/002_ifvarclass.x.cf:5:7
6+
FAIL: tests/lint/002_ifvarclass.x.cf (1 errors)
7+
Failure, 1 errors in total.

tests/lint/002_ifvarclass.x.cf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bundle agent main
2+
{
3+
reports:
4+
"Hello, CFEngine"
5+
ifvarclass => "cfengine";
6+
}

tests/run-lint-tests.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#/usr/bin/env bash
2+
3+
set -e
4+
# set -x
5+
6+
echo "These tests expect cfengine CLI to be installed globally or in venv"
7+
8+
echo "Looking for CFEngine CLI:"
9+
which cfengine
10+
11+
echo "Check that test files are in expected location:"
12+
ls -al tests/lint/*.cf
13+
14+
mkdir -p tmp
15+
16+
echo "Run lint tests:"
17+
for file in tests/lint/*.cf; do
18+
if echo "$file" | grep -q '\.x\.cf$'; then
19+
# File ends with .x.cf, we expect it to:
20+
# - Fail (non-zero exit code)
21+
# - Output the correct error message
22+
23+
expected="$(echo $file | sed 's/\.x\.cf$/.output.txt/')"
24+
if [ ! -f "$expected" ]; then
25+
echo "FAIL: Missing expected output file: $expected"
26+
exit 1
27+
fi
28+
output="tmp/$(basename $file .x.cf).lint-output.txt"
29+
if cfengine lint "$file" > "$output" 2>&1; then
30+
echo "FAIL: $file - expected lint failure but got success"
31+
exit 1
32+
fi
33+
diff -u "$expected" "$output"
34+
echo "OK (expected failure): $file"
35+
else
36+
# Expect success
37+
if ! cfengine lint "$file"; then
38+
echo "FAIL: $file - expected lint success but got failure"
39+
exit 1
40+
fi
41+
echo "OK: $file"
42+
fi
43+
done
44+
45+
echo "All lint tests successful!"

0 commit comments

Comments
 (0)