This document lists all tests that should be run when making changes to the UnifyWeaver codebase. As features are added, this list will grow to cover new test scenarios.
Run these tests after any significant change:
cd /path/to/UnifyWeaver
# 1. Core constraint system
swipl -q -g "use_module('src/unifyweaver/core/constraint_analyzer'), test_constraint_analyzer, halt."
# 2. Stream compiler (non-recursive predicates)
swipl -q -g "use_module('src/unifyweaver/core/stream_compiler'), test_stream_compiler, halt."
# 3. Recursive compiler (transitive closure, tail recursion)
swipl -q -g "use_module('src/unifyweaver/core/recursive_compiler'), test_recursive_compiler, halt."
# 4. Advanced recursion (linear, mutual, tail with accumulators)
swipl -q -g "use_module('src/unifyweaver/core/advanced/test_advanced'), test_all_advanced, halt."
# 5. Constraint integration tests
swipl -q -g "use_module('src/unifyweaver/core/test_constraints'), test_constraints, halt."
# 6. Generate and run inferred test runner (validates generated bash scripts)
swipl -g "use_module('src/unifyweaver/core/advanced/test_runner_inference'), \
generate_test_runner_inferred('output/advanced/inferred_test_runner.sh'), halt."
bash output/advanced/inferred_test_runner.sh
Module: src/unifyweaver/core/constraint_analyzer.pl
What it tests:
Run:
swipl -q -g "use_module('src/unifyweaver/core/constraint_analyzer'), test_constraint_analyzer, halt."
Expected output: All 6 tests pass with ✓ marks
Module: src/unifyweaver/core/stream_compiler.pl
What it tests:
Run:
swipl -q -g "use_module('src/unifyweaver/core/stream_compiler'), test_stream_compiler, halt."
Expected output:
output/ directoryVerify generated code:
bash output/test.sh # Run the generated test script
Module: src/unifyweaver/core/recursive_compiler.pl
What it tests:
Run:
swipl -q -g "use_module('src/unifyweaver/core/recursive_compiler'), test_recursive_compiler, halt."
Expected output:
Verify generated code:
bash output/test_recursive.sh # Run the generated test script
Module: src/unifyweaver/core/advanced/test_advanced.pl
What it tests:
Run:
swipl -q -g "use_module('src/unifyweaver/core/advanced/test_advanced'), test_all_advanced, halt."
Expected output:
Total: 24/24 tests passing (100%)
Verify generated code:
ls -lh output/advanced/
head -30 output/advanced/list_length.sh
bash output/advanced/test_runner.sh # Run all generated scripts
Module: src/unifyweaver/core/advanced/test_runner_inference.pl
What it does: Automatically generates comprehensive test runners by analyzing compiled bash scripts - no manual configuration required!
Features:
output/advanced/ for all .sh filesHow to use:
# Generate inferred test runner
swipl -g "use_module('src/unifyweaver/core/advanced/test_runner_inference'), \
generate_test_runner_inferred('output/advanced/inferred_test_runner.sh'), \
halt."
# Run the generated test runner
bash output/advanced/inferred_test_runner.sh
Generated Output Modes:
Example Generated Test:
# Test count_items.sh (multi-function: 2 functions)
if [[ -f count_items.sh ]]; then
echo "--- Testing count_items.sh ---"
source count_items.sh
# Function: count_items_eval
echo "Test 1: Generic test"
count_items_eval
# Function: count_items
echo "Test 1: Empty list with accumulator 0"
count_items "[]" "0" ""
echo "Test 2: List with elements"
count_items "[a,b,c]" "0" ""
fi
What gets tested:
count_items.sh - Tail recursive accumulator patternsum_list.sh - Tail recursive with arithmeticlist_length.sh - Linear recursion with memoizationfactorial.sh - Linear recursioneven_odd.sh - Mutual recursion (is_even + is_odd)What gets skipped:
demo.sh - Demo scripts (inline execution, no functions)test_*.sh - Test wrappers (duplicates of base scripts)*_stream, *_memo)Implementation Details:
Three-phase implementation:
Phase 1: Classification & Deduplication (Commit 0fbf0a0)
% Classify scripts by type
classify_script_type(Content, Type) :-
% Returns: function_library, demo, test_wrapper, or standalone
% Skip duplicates
is_test_wrapper_duplicate(FileName) :-
atom_concat('test_', _BaseName, FileName).
Phase 2: Multi-Function Extraction (Commit ebac072)
% Extract ALL functions from a script
extract_all_functions(Content, Functions) :-
re_foldl(collect_function, "^(\w+)\(\)\s*\{", Content, [], Functions, [...]).
% Get arity for each function
extract_function_arity(Content, FuncName, Arity) :-
% Count "local var=\"$N\"" patterns in function body
Phase 3: File Grouping (Commit c1c5e64)
% Group test configs by source file
group_configs_by_file(Configs, GroupedConfigs) :-
% Source each file only once, test all its functions
% Write tests for multi-function files
write_file_tests(Stream, FilePath, FunctionConfigs) :-
format(Stream, '# Test ~w (multi-function: ~w functions)~n', [...])
Advantages over manual configuration:
When to use:
Troubleshooting:
function_librarylocal var=\"$N\" patterns in function bodyModule: src/unifyweaver/core/test_constraints.pl
What it tests:
Run:
swipl -q -g "use_module('src/unifyweaver/core/test_constraints'), test_constraints, halt."
Expected output: All 4 integration tests pass with ✓ marks
Constraint Support in Advanced Compilers:
get_constraints/2.tail_recursion compiler now actively uses the unique(true) constraint to generate optimized code with an early exit.Module: examples/constraints_demo.pl
What it demonstrates:
Run:
swipl -q -g "['examples/constraints_demo.pl'], demo, halt."
Verify generated files:
ls -lh output/demo_*.sh
head -20 output/demo_default.sh # Should show: sort -u
head -20 output/demo_ordered.sh # Should show: declare -A seen
head -20 output/demo_no_dedup.sh # Should show: no deduplication
After making changes, verify:
bash -n)Individual module functionality:
constraint_analyzer.pl:test_constraint_analyzer/0call_graph.pl:test_call_graph/0scc_detection.pl:test_scc_detection/0pattern_matchers.pl:test_pattern_matchers/0tail_recursion.pl:test_tail_recursion/0linear_recursion.pl:test_linear_recursion/0mutual_recursion.pl:test_mutual_recursion/0Cross-module functionality:
stream_compiler.pl:test_stream_compiler/0recursive_compiler.pl:test_recursive_compiler/0advanced_recursive_compiler.pl:test_advanced_compiler/0test_constraints.pl:test_constraints/0test_advanced.pl:test_all_advanced/0Ensure no breaking changes:
When adding a new feature, update this document with:
### X. New Feature Tests
**Module:** `src/unifyweaver/core/new_feature.pl`
**What it tests:**
- Feature aspect 1
- Feature aspect 2
**Run:**
```bash
swipl -q -g "use_module('src/unifyweaver/core/new_feature'), test_new_feature, halt."
Expected output: Description of success
Verify:
# Commands to verify functionality
---
## Test Environment (test_env)
UnifyWeaver provides test environment setup scripts that create standalone test directories with auto-discovery:
### Setup
**Bash/Linux:**
```bash
cd scripts/testing
./init_testing.sh # Creates test_env/ in scripts/testing/
./init_testing.sh -d /tmp # Creates /tmp/test_env/
PowerShell/Windows:
cd scripts\testing
.\Init-TestEnvironment.ps1 # Creates test_env/ in scripts\testing\
Hybrid Test Discovery:
test_stream, test_recursive, test_advanced, test_constraints - always available, guaranteed to worktest_*.pl files in src/unifyweaver/core/ and src/unifyweaver/core/advanced/Available Commands:
% Core loaders
?- load_stream. # Load stream compiler
?- load_recursive. # Load recursive compiler
?- load_all_core. # Load all core modules
% Manual tests (reliable fallback)
?- test_stream. # Test stream compiler
?- test_recursive. # Test recursive compiler
?- test_advanced. # Test advanced recursion (24 tests)
?- test_constraints. # Test constraint system
% Auto-discovered tests (if available)
?- test_auto. # Run all auto-discovered tests
% Run everything
?- test_all. # Run ALL tests (manual + auto)
% Help
?- help. # Show all available commands
The test_all command runs all tests in sequence:
?- test_all.
╔════════════════════════════════════════╗
║ Running All UnifyWeaver Tests ║
╚════════════════════════════════════════╝
═══ Manual Tests (Core) ═══
┌─ Stream Compiler ────────────────────┐
=== STREAM COMPILER TESTS ===
... tests run ...
└─ Stream Compiler Complete ──────────┘
┌─ Recursive Compiler ─────────────────┐
... tests run ...
└─ Recursive Compiler Complete ───────┘
┌─ Advanced Recursion ─────────────────┐
... 24 tests run ...
└─ Advanced Recursion Complete ───────┘
┌─ Constraint System ──────────────────┐
... tests run ...
└─ Constraint System Complete ────────┘
═══ Auto-Discovered Tests ═══
(runs any additional test modules found)
╔════════════════════════════════════════╗
║ All Tests Complete ║
╚════════════════════════════════════════╝
No configuration needed! Just create your test file:
src/unifyweaver/core/test_myfeature.pltest_myfeature/0 predicateExample:
:- module(test_myfeature, [test_myfeature/0]).
test_myfeature :-
writeln('=== MY FEATURE TESTS ==='),
% ... your tests ...
writeln('=== TESTS COMPLETE ===').
Then in test environment:
?- help.
% Shows: test_myfeature. - Test myfeature module
?- test_myfeature.
% Runs your tests
?- test_all.
% Includes your tests automatically
For CI/CD integration, all tests can be run in sequence:
#!/bin/bash
# run_all_tests.sh
set -e # Exit on first failure
echo "Running UnifyWeaver test suite..."
# Core tests
echo "1. Constraint analyzer..."
swipl -q -g "use_module('src/unifyweaver/core/constraint_analyzer'), test_constraint_analyzer, halt."
echo "2. Stream compiler..."
swipl -q -g "use_module('src/unifyweaver/core/stream_compiler'), test_stream_compiler, halt."
echo "3. Recursive compiler..."
swipl -q -g "use_module('src/unifyweaver/core/recursive_compiler'), test_recursive_compiler, halt."
echo "4. Advanced recursion..."
swipl -q -g "use_module('src/unifyweaver/core/advanced/test_advanced'), test_all_advanced, halt."
echo "5. Constraint integration..."
swipl -q -g "use_module('src/unifyweaver/core/test_constraints'), test_constraints, halt."
echo ""
echo "✓ All tests passed!"
examples/ directorySee the dedicated plan at docs/development/testing/v0_1_csharp_test_plan.md for full details.
SKIP_CSHARP_EXECUTION=1 \
swipl -q \
-f tests/core/test_csharp_query_target.pl \
-g test_csharp_query_target:test_csharp_query_target \
-t halt
SKIP_CSHARP_EXECUTION=1 swipl -q -f run_all_tests.pl -g main -t halt
Follow the “Manual Runtime Validation” section in the plan to:
output/csharp/<uuid>/.dotnet build --no-restore.dotnet bin/Debug/net9.0/<module>.dll or the self-contained executable) and verify outputs (alice,charlie, 0, 2, 4).Module not found:
ERROR: source_sink `...` does not exist
Solution: Ensure you’re running from the UnifyWeaver root directory
Test predicates not exported:
ERROR: Unknown procedure: test_foo/0
Solution: Check module declaration exports the test predicate
Output directory missing:
ERROR: existence_error(directory,output)
Solution: Create directory: mkdir -p output/advanced
Bash script errors:
bash: output/test.sh: No such file or directory
Solution: Run the Prolog test first to generate the files
As features are added, tests should be created for:
Last updated: 2025-10-06