💾 Archived View for gmi.noulin.net › gitRepositories › blockFile › file › runMemtest.c.gmi captured on 2023-01-29 at 13:21:13. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
runMemtest.c (2355B)
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 #define internal static 13 14 #include <stdlib.h> 15 #include <stdio.h> 16 17 int argc; char **argv; 18 19 enum {START, TEST, TESTEND, SEARCH}; 20 21 int main(int ARGC, char** ARGV) { 22 char **list = NULL; 23 char **tests = NULL; 24 char **functions = NULL; 25 char **result = NULL; 26 27 argc = ARGC; argv = ARGV;;// 28 29 initLibsheepy(argv[0]); 30 31 if (argc < 3) { 32 printf("Give a parameter: unit test c file and template file"); 33 printf("\n"); 34 XFAILURE; 35 } 36 37 // get function list from argv[1] 38 list = readText(argv[1]); 39 40 int status = START;; 41 forEachCharP(list, e) { 42 if (status != START) { 43 if (findS(*e, "#include")) { 44 listPushS(&tests, *e); 45 continue; 46 } 47 if (findS(*e, "START_TEST(")) { 48 char **l = split(*e, "("); 49 char **l2 = split(l[1], ")");; 50 iAppendS(&l2[0], "();"); 51 listPushS(&functions, l2[0]); 52 listFreeManyS(l,l2); 53 iReplaceManyS(e, "START_TEST(", "void ", ")", "(void) {"); 54 status = TEST; 55 } 56 if (findS(*e, "END_TEST")) { 57 iReplaceS(e, "END_TEST", "}",0); 58 status = TESTEND; 59 } 60 if (status == SEARCH) { 61 char *s = sliceS(*e, 0, 5);; 62 if (strEq(s, "Suite")) { 63 break; 64 } 65 free(s); 66 listPushS(&tests, *e); 67 continue; 68 } 69 if ((status == TEST) || (status == TESTEND)) { 70 listPushS(&tests, *e); 71 if (status == TESTEND) { 72 status = SEARCH; 73 } 74 } 75 } 76 else if (findS(*e, "START MEM TEST ANCHOR")) { 77 status = SEARCH; 78 } 79 } 80 81 listFreeS(list); 82 83 //listPrintS(tests); 84 //listPrintS(functions); 85 86 // read template 87 char **template = readText(argv[2]); 88 89 // process template 90 forEachCharP(template, e) { 91 if (findS(*e, "__tests")) { 92 listAppendS(&result, tests); 93 } 94 else if (findS(*e, "__calls")) { 95 listAppendS(&result, functions); 96 } 97 else { 98 listPushS(&result, *e); 99 } 100 } 101 102 // save result 103 char *fileName = sliceS(argv[1], 0, -2); 104 iAppendS(&fileName, "Mem.c"); 105 printf("%s\n", fileName); 106 writeText(fileName, result); 107 108 free(fileName); 109 listFreeManyS(tests, functions, result, template); 110 111 XSUCCESS; 112 }