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