Add integration test framework
This commit is contained in:
@@ -12,4 +12,10 @@ generate_golden::
|
|||||||
clean::
|
clean::
|
||||||
rm -f c2
|
rm -f c2
|
||||||
|
|
||||||
include v0/include.mk
|
include v0/include.mk
|
||||||
|
|
||||||
|
integration-test: v0/bin/c2 v0/bin/test_integration
|
||||||
|
./v0/bin/test_integration
|
||||||
|
|
||||||
|
v0/bin/test_integration: v0/test_integration.c
|
||||||
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
@@ -13,5 +13,21 @@ In order to run the tests, run `make test`.
|
|||||||
## Versioning
|
## Versioning
|
||||||
The current version is v0. Its source code lives in the `v0` directory.
|
The current version is v0. Its source code lives in the `v0` directory.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
### Unit Tests
|
||||||
|
Run unit tests with:
|
||||||
|
```bash
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Integration Tests
|
||||||
|
Integration tests compare the compiler output with expected C files.
|
||||||
|
To add a new integration test, create a new directory under `v0/integration_tests/` with `input.c2` and `expected.c` files.
|
||||||
|
Run integration tests with:
|
||||||
|
```bash
|
||||||
|
make integration-test
|
||||||
|
```
|
||||||
|
|
||||||
## Languages Specifications
|
## Languages Specifications
|
||||||
See the specs directory for information on the actual language syntax.
|
See the specs directory for information on the actual language syntax.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Hello, world
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
module simple;
|
||||||
|
u32 x = 123;
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
int run_test(const char* dir_name) {
|
||||||
|
char cmd[2048];
|
||||||
|
char input_path[1024];
|
||||||
|
char expected_path[1024];
|
||||||
|
|
||||||
|
snprintf(input_path, sizeof(input_path), "v0/integration_tests/%s/input.c2", dir_name);
|
||||||
|
snprintf(expected_path, sizeof(expected_path), "v0/integration_tests/%s/expected.c", dir_name);
|
||||||
|
|
||||||
|
if (snprintf(cmd, sizeof(cmd), "./v0/bin/c2 %s > actual.c", input_path) >= sizeof(cmd)) {
|
||||||
|
printf("Command buffer too small for %s\n", dir_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (system(cmd) != 0) {
|
||||||
|
printf("Failed to run compiler for %s\n", dir_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snprintf(cmd, sizeof(cmd), "diff -u %s actual.c", expected_path) >= sizeof(cmd)) {
|
||||||
|
printf("Command buffer too small for %s\n", dir_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (system(cmd) != 0) {
|
||||||
|
printf("Test %s failed: Output mismatch\n", dir_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test %s passed\n", dir_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
DIR* d = opendir("v0/integration_tests");
|
||||||
|
if (!d) {
|
||||||
|
perror("opendir");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent* dir;
|
||||||
|
int passed = 0;
|
||||||
|
int failed = 0;
|
||||||
|
|
||||||
|
while ((dir = readdir(d)) != NULL) {
|
||||||
|
if (dir->d_type == DT_DIR && strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0) {
|
||||||
|
if (run_test(dir->d_name) == 0) {
|
||||||
|
passed++;
|
||||||
|
} else {
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
|
||||||
|
printf("\nTotal tests: %d, Passed: %d, Failed: %d\n", passed + failed, passed, failed);
|
||||||
|
return failed > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user