#include <stdio.h>
#include <stdlib.h>

#define TEST_COUNT 9
#define COMMAND_SIZE 128

int main(void)
{
    int failure = 0;
    int res[TEST_COUNT];
    for (size_t i = 1; i <= TEST_COUNT; i++)
    {
        char command[COMMAND_SIZE];
        sprintf(command,"valgrind --track-origins=yes -s ./parser -caff test_cases/%ld.caff",i);
        res[i-1] = system(command);
        printf("Test %ld result: %d (%s)\n",i, res[i-1], ( i > 3 ? res[i-1]== 65280 : res[i-1]== 0) ? "SUCCESS" : "FAIL");
        failure += (i > 3 ? res[i-1]== 65280 : res[i-1]== 0) ? 0 : 1;
    }

    printf("Summary:\n");
    for (size_t i = 0; i < TEST_COUNT; i++)
    {
        printf("Test %ld result: %s\n",i+1, ( i > 2 ? res[i]== 65280 : res[i]== 0) ? "PASS" : "FAIL");
    }

    return (failure == 0) ?  EXIT_SUCCESS : EXIT_FAILURE;
}