Greg Ward avatar Greg Ward committed 1635d6a

Add "make grind" to run (some) tests under valgrind; start fixing leaks.

Comments (0)

Files changed (3)

 check-simple: vcprompt
 	cd tests && ./test-simple
 
+grind: check-simple
+	(cd tests && VCPVALGRIND=y ./test-simple)
+
 check-hg: vcprompt $(hgrepo)
 	cd tests && ./test-hg
 
 
     if (!read_first_line(".svn/entries", buf, 1024)) {
         debug("failed to read from .svn/entries: assuming not an svn repo");
-        return NULL;
+        goto err;
     }
     else {
         FILE *fp;
                     fgets(line, sizeof(line), fp) == NULL) {
                     debug("early EOF reading .svn/entries");
                     fclose(fp);
-                    return NULL;
+                    goto err;
                 }
 
                 // Get the revision number
                 else {
                     debug("early EOF: expected revision number");
                     fclose(fp);
-                    return NULL;
+                    goto err;
                 }
             }
             else {
                         break;
                 if (p == NULL) {
                     debug("no 'revision=' line found in .svn/entries");
-                    return NULL;
+                    goto err;
                 }
                 if (sscanf(p, " %*[^\"]\"%[0-9]\"", rev) == 1) {
                     result_set_revision(result, rev, -1);
         fclose(fp);
     }
     return result;
+ err:
+    free(result);
+    return NULL;
 }
 
 vccontext_t*
         format="%b"
     fi
 
-    if [ "$format" != '-' ]; then
-        actual=`VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $vcprompt -f "$format"`
-    else
-        actual=`VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $vcprompt`
+    prefix=""
+    if [ "$VCPVALGRIND" ]; then
+        prefix="valgrind --leak-check=full --error-exitcode=99 -q "
     fi
 
-    if [ "$expect" != "$actual" ]; then
+    if [ "$format" != '-' ]; then
+        cmd='VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $prefix$vcprompt -f "$format"'
+    else
+        cmd='VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $prefix$vcprompt'
+    fi
+    actual=`eval $cmd`
+    status=$?
+
+    if [ $status -ne 0 ]; then
+        echo "fail: child process terminated with exit status $status; command was:" >&2
+        eval echo $cmd >&2
+        failed="y"
+        return $status
+    elif [ "$expect" != "$actual" ]; then
         echo "fail: $message: expected \"$expect\", but got \"$actual\"" >&2
         failed="y"
         return 1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.