-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.c
55 lines (50 loc) · 1.88 KB
/
parse_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdbool.h>
#include "parse_text.h"
#include "parser.h"
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
printf("FORMAT: test_parse <file_to_test(e.g. test.make)>");
exit(1);
}
FILE *mfp = open_makefile(true, argv[1]);
BuildSpecList bsl;
bsl.len = 0;
getBuildSpecList(&bsl, mfp);
int numErr = 0;
if (strcmp(bsl.frstBS->target, "target1:")) {
numErr++;
printf("ERROR: first target != target1:, its %s\n", bsl.frstBS->target);
}
if (strcmp(bsl.frstBS->cmds->lstCmd->argv[0], "gcc")) {
numErr++;
printf("ERROR: first targets cmd != gcc, its %s\n", bsl.frstBS->cmds->lstCmd->argv[0]);
}
int i, j, k;
for (i = 0; i < bsl.frstBS->cmds->frstCmd->argc; i++) {
printf("%s ", bsl.frstBS->cmds->frstCmd->argv[i]);
}
printf("\nShould be: gcc -o file.txt file2.c \n");
BuildSpec *currBuildSpec = bsl.frstBS;
Command *currCmd;
for (i = 0; i < bsl.len; i++) {
printf("BUILD SPEC #%d || TARGET: %s || NUM CMDS: %d || NUM DEPS: %d \n", i, currBuildSpec->target, currBuildSpec->cmds->len, currBuildSpec->depsLen);
for (j = 0; j < currBuildSpec->depsLen; j++) {
printf("\tDEP #%d: %s\n", j, currBuildSpec->deps[j]);
}
if (currBuildSpec->cmds->len >= 1) currCmd = currBuildSpec->cmds->frstCmd;
for (j = 0; j < currBuildSpec->cmds->len; j++) {
printf("\tCMD #%d\n", j);
for (k = 0; k < currCmd->argc; k++) {
printf("\t\tARGV[%d] == %s\n",k, currCmd->argv[k]);
}
currCmd = currCmd->nxtCmd;
}
currBuildSpec = currBuildSpec->nxtBuildSpec;
}
if (numErr == 0) printf("SUCCESS, ALL TESTS PASSED\n");
else printf("NUM ERRORS: %d\n", numErr);
// printf("ARG[0]: %s\n", bsl.lstBS->target);
}