runMemtest.c (2286B)
1 #! /usr/bin/env sheepy 2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */ 3 4 // 5 // in unit test file, add line: 6 // //START MEM TEST ANCHOR 7 // 8 // 9 10 #include "libsheepyObject.h" 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 15 int argc; char **argv; 16 17 enum {START, TEST, TESTEND, SEARCH}; 18 19 int main(int ARGC, char** ARGV) { 20 char **list = NULL; 21 char **tests = NULL; 22 char **functions = NULL; 23 char **result = NULL; 24 25 argc = ARGC; argv = ARGV;;// 26 27 initLibsheepy(argv[0]); 28 29 if (argc < 3) { 30 printf("Give a parameter: unit test c file and template file"); 31 printf("\n"); 32 XFAILURE; 33 } 34 35 // get function list from argv[1] 36 list = readText(argv[1]); 37 38 int status = START;; 39 forEachCharP(list, e) { 40 if (status != START) { 41 if (findS(*e, "#include")) { 42 listPushS(&tests, *e); 43 continue; 44 } 45 if (findS(*e, "START_TEST(")) { 46 char **l = split(*e, "("); 47 char **l2 = split(l[1], ")");; 48 iAppendS(&l2[0], "();"); 49 listPushS(&functions, l2[0]); 50 listFreeManyS(l,l2); 51 iReplaceManyS(e, "START_TEST(", "void ", ")", "(void) {"); 52 status = TEST; 53 } 54 if (findS(*e, "END_TEST")) { 55 iReplaceS(e, "END_TEST", "}",0); 56 status = TESTEND; 57 } 58 if (status == SEARCH) { 59 char *s = sliceS(*e, 0, 5);; 60 if (strEq(s, "Suite")) { 61 break; 62 } 63 free(s); 64 listPushS(&tests, *e); 65 continue; 66 } 67 if ((status == TEST) || (status == TESTEND)) { 68 listPushS(&tests, *e); 69 if (status == TESTEND) { 70 status = SEARCH; 71 } 72 } 73 } 74 else if (findS(*e, "START MEM TEST ANCHOR")) { 75 status = SEARCH; 76 } 77 } 78 79 listFreeS(list); 80 81 //listPrintS(tests); 82 //listPrintS(functions); 83 84 // read template 85 char **template = readText(argv[2]); 86 87 // process template 88 forEachCharP(template, e) { 89 if (findS(*e, "__tests")) { 90 listAppendS(&result, tests); 91 } 92 else if (findS(*e, "__calls")) { 93 listAppendS(&result, functions); 94 } 95 else { 96 listPushS(&result, *e); 97 } 98 } 99 100 // save result 101 putsG("./memcheckVersion.c"); 102 writeText("./memcheckVersion.c", result); 103 104 listFreeManyS(tests, functions, result, template); 105 106 XSUCCESS; 107 } 108 ```