]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/run_tests.c
ccanlint: rename structures to match keys
[ccan] / tools / ccanlint / tests / run_tests.c
index 875ba758e43a70a036d3290c6ecf11effe3bc41c..0edfad262c4ba02299052231691b23ce40784ff7 100644 (file)
@@ -2,6 +2,7 @@
 #include <tools/tools.h>
 #include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
+#include <ccan/foreach/foreach.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -21,68 +22,56 @@ static const char *can_run(struct manifest *m)
        return NULL;
 }
 
-static void *do_run_tests(struct manifest *m)
+static void do_run_tests(struct manifest *m,
+                        bool keep,
+                        unsigned int *timeleft,
+                        struct score *score)
 {
-       struct list_head *list = talloc(m, struct list_head);
-       char *failures = talloc_strdup(m, "");
+       struct list_head *list;
        struct ccan_file *i;
+       char *cmdout;
 
-       list_head_init(list);
-
-       list_for_each(&m->run_tests, i, list) {
-               char *testout;
-               run_tests.total_score++;
-               /* FIXME: timeout here */
-               testout = run_command(m, i->compiled);
-               if (!testout)
-                       continue;
-               failures = talloc_asprintf_append(failures,
-                                                 "Running %s failed:\n",
-                                                 i->name);
-               failures = talloc_append_string(failures, testout);
-       }
-
-       list_for_each(&m->api_tests, i, list) {
-               char *testout;
-               run_tests.total_score++;
-               /* FIXME: timeout here */
-               testout = run_command(m, i->compiled);
-               if (!testout)
-                       continue;
-               failures = talloc_asprintf_append(failures,
-                                                 "Running %s failed:\n",
-                                                 i->name);
-               failures = talloc_append_string(failures, testout);
-       }
-
-       if (streq(failures, "")) {
-               talloc_free(failures);
-               failures = NULL;
+       score->total = 0;
+       foreach_ptr(list, &m->run_tests, &m->api_tests) {
+               list_for_each(list, i, list) {
+                       score->total++;
+                       if (run_command(m, timeleft, &cmdout, "%s",
+                                       i->compiled))
+                               score->score++;
+                       else
+                               score_file_error(score, i, 0, cmdout);
+               }
        }
 
-       return failures;
+       if (score->score == score->total)
+               score->pass = true;
 }
 
-static unsigned int score_run_tests(struct manifest *m, void *check_result)
-{
-       /* FIXME: be cleverer here */
-       return 0;
-}
+/* Gcc's warn_unused_result is fascist bullshit. */
+#define doesnt_matter()
 
-static const char *describe_run_tests(struct manifest *m,
-                                         void *check_result)
+static void run_under_debugger(struct manifest *m, struct score *score)
 {
-       char *descrip = talloc_strdup(check_result, "Running tests failed:\n");
+       char *command;
+       struct file_error *first;
+
+       if (!ask("Should I run the first failing test under the debugger?"))
+               return;
 
-       return talloc_append_string(descrip, check_result);
+       first = list_top(&score->per_file_errors, struct file_error, list);
+       command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s",
+                                 first->file->compiled);
+       if (system(command))
+               doesnt_matter();
 }
 
-struct ccanlint run_tests = {
-       .name = "run and api tests run successfully",
-       .score = score_run_tests,
+struct ccanlint tests_pass = {
+       .key = "tests_pass",
+       .name = "Module's run and api tests pass",
        .check = do_run_tests,
-       .describe = describe_run_tests,
+       .handle = run_under_debugger,
        .can_run = can_run,
+       .needs = "tests_compile"
 };
 
-REGISTER_TEST(run_tests, &compile_tests, NULL);
+REGISTER_TEST(tests_pass);