64 lines
1.7 KiB
C
64 lines
1.7 KiB
C
#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;
|
|
}
|