115 lines
2.8 KiB
Markdown
115 lines
2.8 KiB
Markdown
# Running the Codegen Tests
|
|
|
|
## Quick Start
|
|
|
|
```bash
|
|
# Regenerate C code from all tests
|
|
for f in tests/codegen/*.sui; do
|
|
./target/debug/suicmez "$f"
|
|
done
|
|
|
|
# Compile and run a single test
|
|
gcc tests/codegen/test_comprehensive.c -o /tmp/test_comprehensive
|
|
/tmp/test_comprehensive
|
|
```
|
|
|
|
## Test Summary
|
|
|
|
| Test | Purpose | Input | Output |
|
|
|------|---------|-------|--------|
|
|
| `test_executable.sui` | Simple arithmetic | Basic int operations | Exit code with result |
|
|
| `test_array_simple.sui` | Array operations | Array literal and indexing | Debug output with array values |
|
|
| `test_enum_simple.sui` | Enum types | Enum variant creation | Discriminant value |
|
|
| `test_comprehensive.sui` | Mixed types | All basic + complex types | Full debug trace |
|
|
| `test_all_types.sui` | Type coverage | Every language type | Debug output for each |
|
|
|
|
## Running Individual Tests
|
|
|
|
### 1. Array Test
|
|
```bash
|
|
./target/debug/suicmez tests/codegen/test_array_simple.sui
|
|
gcc tests/codegen/test_array_simple.c -o /tmp/array_test
|
|
/tmp/array_test
|
|
```
|
|
|
|
**Expected Output:**
|
|
```
|
|
| int* arr = (int[]){1, 2, 3} |
|
|
0x...
|
|
| int x = arr[0] |
|
|
1
|
|
```
|
|
|
|
### 2. Enum Test
|
|
```bash
|
|
./target/debug/suicmez tests/codegen/test_enum_simple.sui
|
|
gcc tests/codegen/test_enum_simple.c -o /tmp/enum_test
|
|
/tmp/enum_test
|
|
```
|
|
|
|
**Expected Output:**
|
|
```
|
|
| struct Color c = (struct Color){ .discriminant = 0, .data = { .red = (struct Color_Red){} } } |
|
|
0
|
|
```
|
|
|
|
### 3. Comprehensive Test
|
|
```bash
|
|
./target/debug/suicmez tests/codegen/test_comprehensive.sui
|
|
gcc tests/codegen/test_comprehensive.c -o /tmp/comprehensive_test
|
|
/tmp/comprehensive_test
|
|
```
|
|
|
|
**Expected Output:** (full debug trace of all operations)
|
|
```
|
|
| int x = 10 |
|
|
10
|
|
| int y = 20 |
|
|
20
|
|
| int sum = add(x, y) |
|
|
30
|
|
... (more output)
|
|
```
|
|
|
|
## Debugging the Codegen
|
|
|
|
Each test's generated C file includes debug `printf` statements. To see what's happening:
|
|
|
|
1. **Look at the generated C code:**
|
|
```bash
|
|
cat tests/codegen/test_comprehensive.c
|
|
```
|
|
|
|
2. **Run with debug output:**
|
|
```bash
|
|
gcc tests/codegen/test_comprehensive.c -o /tmp/test
|
|
/tmp/test 2>&1 | head -20
|
|
```
|
|
|
|
3. **Check for compilation errors:**
|
|
```bash
|
|
gcc tests/codegen/test_comprehensive.c -c -o /tmp/test.o
|
|
```
|
|
|
|
## Verifying Correctness
|
|
|
|
All tests should:
|
|
- ✅ Generate valid C99 code
|
|
- ✅ Compile without warnings
|
|
- ✅ Execute without segmentation faults
|
|
- ✅ Show proper debug output for each statement
|
|
|
|
## Common Issues
|
|
|
|
### Test fails to compile
|
|
- Check that the `.sui` file was properly transpiled
|
|
- Regenerate with: `./target/debug/suicmez tests/codegen/test_name.sui`
|
|
|
|
### Debug output missing
|
|
- Ensure the printf statements are in the generated C code
|
|
- Check for return statements that might skip debug output
|
|
|
|
### Wrong values printed
|
|
- The debug output uses automatic format specifiers (`%d`, `%f`, `%s`, `%p`)
|
|
- Struct types print the first field value
|
|
- Arrays print the pointer address
|