commit 79d3d9a6e0ae3042dfa356a0eca99ae976077fab
parent 02ab726e5a65c4e565f1e51801f8b6b819e9579d
Author: Remy Noulin <loader2x@gmail.com>
Date: Sat, 19 May 2018 23:46:18 +0200
did my code execute package
dmce.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package.yml | 18 ++++++++++
2 files changed, 136 insertions(+)
Diffstat:
| A | dmce.c | | | 118 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | package.yml | | | 18 | ++++++++++++++++++ |
2 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/dmce.c b/dmce.c
@@ -0,0 +1,118 @@
+//
+
+#include "libsheepyObject.h"
+
+#define internal static
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int MAIN(int ARGC, char** ARGV);
+
+int argc; char **argv;
+
+#ifndef unitTest
+// Remove main when running the unit tests
+#define MAIN main
+#endif
+int MAIN(int ARGC, char** ARGV) {
+ smallArrayt *list = NULL;
+
+ argc = ARGC; argv = ARGV;;// dmce, did my code execute
+ // checks if the code not yet commited has been executed during the unit tests
+ // dmce uses gcov to get the code coverage
+
+ // Steps
+ // list file in current folder
+ // consider gcov files
+ // load gcov file
+ // store source code coverage in coverage list
+ // find out source filename
+ // create git diff command
+ // list diff for the complete code in source file
+ // analyze the diff and code coverage
+
+
+ // list file in current folder
+ list = walkDirO(".");
+
+ forEachSmallArray(list, e) {
+ castS(g, duplicateO(e));
+
+ // consider gcov files
+ // TODO use basename instead of path in g
+ if (hasG(g, ".gcov") && !hasG(g, "./.")) {
+ createAllocateSmallArray(source);
+ createAllocateSmallArray(coverage);
+ createAllocateSmallArray(rawCov);
+
+ // load gcov file
+ // store source code coverage in coverage list
+ readFileG(rawCov, ssGet(g));
+ forEachSmallArray(rawCov, l) {
+ castS(L, l);
+ smallArrayt *line = splitG(L, ":");
+ if (lenG(line) >= 3) {
+ pushNFreeG(coverage, duplicateO(L));
+ }
+ terminateO(line);
+ free(l);
+ }
+ terminateO(rawCov);
+
+ // find out source filename
+ sliceG(g,0,-5);
+ printf("--- %s\n\n", ssGet(g));
+ printf("\n");
+ // create git diff command
+ char *cmd;
+ cmd = appendS("git diff --no-prefix -U100000 ", ssGet(g)); {
+ // list diff for the complete code in source file
+ execO(cmd, source, NULL);
+ free(cmd);
+
+ // analyze the diff and code coverage
+ int status = 0;
+ int lines = 0;
+ forEachSmallArray(source, l) {
+ castS(L, l);
+
+ if (!status) {
+ if (getG(L,0,0) == '@' && getG(L,0,1) == '@') {
+ // found diff start
+ status = 1;
+ }
+ }
+ else {
+ // find code not yet commited
+ if (getG(L,0,0) == '+') {
+ //print 'src: %d - %s', lines, *l
+ //print 'cov: %d - %s', lines+5, coverage[lines+5]
+ // check new lines have been executed
+ smallStringt *s = getG(coverage, rtSmallStringt, lines+5);
+ if (hasG(s, "#####:")) {
+ // print new code that has not been executed in the unit tests
+ printf("%10d: %s", lines, ssGet(L));
+ printf("\n");
+ //print ' cov: %s\n', coverage[lines+5]
+ }
+ free(s);
+ }
+ if (getG(L,0,0) != '-') {
+ // ignore removed lines
+ lines++;
+ }
+ }
+ free(l);
+ }
+
+ terminateO(source);
+ terminateO(coverage);
+ }
+ }
+ terminateO(g);
+ free(e);
+ }
+
+ terminateO(list);
+}
diff --git a/package.yml b/package.yml
@@ -0,0 +1,18 @@
+---
+ name: dmce
+ version: 0.0.1
+ description: dmce compares code coverage to changed lines in a git repo
+ bin: ./dmce.c
+ scripts:
+ test: echo "Error no test specified" && exit 1
+ repository:
+ type: git
+ url: git+https://github.com/RemyNoulin/dmce.git
+ keywords:
+ - utility
+ - command
+ author: Remy Noulin
+ license: MIT
+ bugs:
+ url: https://github.com/RemyNoulin/dmce/issues
+ homepage: https://github.com/RemyNoulin/dmce