dmce.c (2875B)
1 //: generator/pp comment config 2 //:not cScript 3 #include "../release/libsheepy.h" 4 //:end 5 6 #define internal static 7 8 #include <stdlib.h> 9 #include <stdio.h> 10 11 #ifndef unitTest 12 #endif 13 int MAIN(int ARGC, char** ARGV); 14 15 int argc; char **argv; 16 17 #ifndef unitTest 18 // Remove main when running the unit tests 19 #define MAIN main 20 #endif 21 int MAIN(int ARGC, char** ARGV) { 22 char **list = NULL; 23 24 argc = ARGC; argv = ARGV;;// dmce, did my code execute 25 // checks if the code not yet commited has been executed during the unit tests 26 // dmce uses gcov to get the code coverage 27 28 // Steps 29 // list file in current folder 30 // consider gcov files 31 // load gcov file 32 // store source code coverage in coverage list 33 // find out source filename 34 // create git diff command 35 // list diff for the complete code in source file 36 // analyze the diff and code coverage 37 38 // list file in current folder 39 list = walkDir("."); 40 41 forEachCharP(list, e) { 42 // consider gcov files 43 // TODO use basename instead of path in *e 44 if (findS(*e, ".gcov") && !findS(*e, "./.")) { 45 char **source; 46 char **coverage = NULL; 47 char **rawCov; 48 49 // load gcov file 50 // store source code coverage in coverage list 51 rawCov = readText(*e); 52 forEachCharP(rawCov, l) { 53 char **line; 54 line = split(*l, ":"); 55 if (listLengthS(line) >= 3) { 56 pErrorNULL(listPushS(&coverage, *l)); 57 } 58 listFreeS(line); 59 } 60 listFreeS(rawCov); 61 62 // find out source filename 63 char *srcName; 64 srcName = sliceS(*e,0,-5);; 65 printf("--- %s\n\n", srcName); 66 printf("\n"); 67 68 // create git diff command 69 char *cmd; 70 cmd = appendS("git diff --no-prefix -U100000 ", srcName); { 71 // list diff for the complete code in source file 72 source = execOut(cmd); 73 freeManyS(srcName, cmd); 74 75 // analyze the diff and code coverage 76 int status = 0; 77 int lines = 0; 78 forEachCharP(source, l) { 79 if (!status) { 80 if ((*l)[0] == '@' && (*l)[1] == '@') { 81 // found diff start 82 status = 1; 83 } 84 } 85 else { 86 // find code not yet commited 87 if ((*l)[0] == '+') { 88 //print 'src: %d - %s', lines, *l 89 //print 'cov: %d - %s', lines+5, coverage[lines+5] 90 // check new lines have been executed 91 if (findS(coverage[lines+5], "#####:")) { 92 // print new code that has not been executed in the unit tests 93 printf("%10d: %s", lines, *l); 94 printf("\n"); 95 //print ' cov: %s\n', coverage[lines+5] 96 } 97 } 98 if ((*l)[0] != '-') { 99 // ignore removed lines 100 lines++; 101 } 102 } 103 } 104 105 listFreeManyS(source, coverage); 106 } 107 } 108 } 109 110 listFreeS(list); 111 }