4.6 KiB
4.6 KiB
Codegen Tests - Summary
Organization
The codegen tests have been organized into a dedicated tests/codegen/ subdirectory with the following structure:
tests/codegen/
├── README.md # Comprehensive documentation
├── TESTING.md # Testing instructions
├── SUMMARY.md # This file
├── test_executable.* # Simple arithmetic test
├── test_array_simple.* # Array operations test
├── test_enum_simple.* # Enum types test
├── test_comprehensive.* # Mixed types test
└── test_all_types.* # Type coverage test
Each test has two files:
.sui- Source code in the suicmez language.c- Generated C code with debug output
What Was Cleaned Up
Removed from root directory:
simple.sui,simple_test.*- Incomplete test filessyntax_test.sui- Old syntax explorationtest_affine.sui,test_binding.sui- Abandoned teststest_linear*.sui- Linear type system experimentstest_scoping.sui,test_shadow.sui- Scoping tests- Other misc test files
Kept in root (valid existing tests):
- None - all valid tests are now organized in
tests/subdirectories
Test Files
New Codegen Tests (in tests/codegen/)
-
test_executable - Minimal executable test
- Basic integer operations
- Function calls
- Return values
-
test_array_simple - Array functionality
- Array literals:
[1, 2, 3] - Array indexing:
arr[0] - Pointer-based array representation
- Array literals:
-
test_enum_simple - Enumeration types
- Enum variants
- Discriminant + union pattern
- Struct ordering
-
test_comprehensive - Combined features
- All basic types (int, float, bool, string)
- Structs with multiple fields
- Enums with variants
- Arrays with complex operations
- Function calls with parameters
-
test_all_types - Complete type coverage
- Exhaustive test of all language types
- Demonstrates each type independently
- Shows debug output for each
Existing Tests (preserved in tests/)
arrays.sui- Additional array testsbasic_types.sui/c- Basic type testscontrol_flow.sui/c- If/while/for loopsenums.sui- Enum functionalityfunctions.sui/c- Function definitionsgenerics_comprehensive.sui/c- Generic typesimport_tests/- Module importspointers.sui- Pointer operationsstructs.sui/c- Struct definitionstraits.sui/c- Trait system- And more...
Features Demonstrated
Memory Management
- Stack allocation:
int,float,bool - Heap allocation: arrays with pointers
- Strings as
char* - Structs and enums stack-allocated
Language Features
- Variable declarations and assignments
- Function definitions and calls
- Struct literals with initialization
- Enum variants with discriminants
- Array literals and indexing
- Type conversions (implicit)
Debug Output
Every statement generates debug output:
int x = 10;
printf("| int x = 10 | \n %d\n", x);
// Output: | int x = 10 |
// 10
Running the Tests
Quick Check
cd /home/nafi/langjam/suicmez
for f in tests/codegen/*.sui; do
./target/debug/suicmez "$f" > /dev/null && echo "✓ $(basename $f)"
done
Full Test Run
# Regenerate all C code
for f in tests/codegen/*.sui; do
./target/debug/suicmez "$f"
done
# Compile all tests
for f in tests/codegen/*.c; do
gcc "$f" -o "/tmp/$(basename ${f%.c})"
done
# Run all tests
for exe in /tmp/test_*; do
echo "Running $(basename $exe)..."
"$exe" 2>&1 | head -5
echo ""
done
Individual Test
./target/debug/suicmez tests/codegen/test_comprehensive.sui
gcc tests/codegen/test_comprehensive.c -o /tmp/test
/tmp/test
Quality Assurance
All codegen tests:
- ✅ Generate valid C99 code
- ✅ Compile with GCC without errors
- ✅ Execute successfully
- ✅ Display proper debug output
- ✅ Return correct values
- ✅ Include comprehensive documentation
Documentation
- README.md - Feature overview and structure
- TESTING.md - How to run and troubleshoot tests
- SUMMARY.md - This file, organization summary
Next Steps
To add new codegen tests:
- Create
test_feature.suiintests/codegen/ - Run transpiler:
./target/debug/suicmez tests/codegen/test_feature.sui - Verify C code:
gcc tests/codegen/test_feature.c -c - Test execution:
gcc tests/codegen/test_feature.c -o /tmp/test && /tmp/test - Document in README.md
Files Status
✅ All files properly organized
✅ All tests generate valid C code
✅ All tests compile and run
✅ Documentation complete
✅ Debug output working
✅ Root directory cleaned