]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: make fewer tests compulsory.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 15 Nov 2011 02:12:25 +0000 (12:42 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 15 Nov 2011 02:12:25 +0000 (12:42 +1030)
Compulsory means "malformed", we might get rid of it altogether, since
any test can mark "fail" and make ccanlint exit with non-zero status.

Now we only have four compulsory tests:
   info_exists               Module has _info file
   depends_exist             Module's CCAN dependencies can be found
   objects_build             Module object files can be built
   module_builds             Module can be built from object files

tools/ccanlint/compulsory_tests/depends_build.c [deleted file]
tools/ccanlint/compulsory_tests/main_header_compiles.c [deleted file]
tools/ccanlint/compulsory_tests/main_header_exists.c [deleted file]
tools/ccanlint/compulsory_tests/module_links.c [deleted file]
tools/ccanlint/tests/depends_build.c [new file with mode: 0644]
tools/ccanlint/tests/main_header_compiles.c [new file with mode: 0644]
tools/ccanlint/tests/main_header_exists.c [new file with mode: 0644]
tools/ccanlint/tests/module_links.c [new file with mode: 0644]

diff --git a/tools/ccanlint/compulsory_tests/depends_build.c b/tools/ccanlint/compulsory_tests/depends_build.c
deleted file mode 100644 (file)
index ea5c392..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-#include <tools/ccanlint/ccanlint.h>
-#include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/str/str.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <string.h>
-#include <ctype.h>
-#include "build.h"
-
-static const char *can_build(struct manifest *m)
-{
-       if (safe_mode)
-               return "Safe mode enabled";
-       return NULL;
-}
-
-static bool expect_obj_file(struct manifest *m)
-{
-       /* If it has C files, we expect an object file built from them. */
-       return !list_empty(&m->c_files);
-}
-
-static char *build_subdir_objs(struct manifest *m,
-                              const char *flags,
-                              enum compile_type ctype)
-{
-       struct ccan_file *i;
-
-       list_for_each(&m->c_files, i, list) {
-               char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
-               char *output;
-
-               i->compiled[ctype] = maybe_temp_file(m, "", false, fullfile);
-               if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
-                                   i->compiled[ctype], &output)) {
-                       talloc_free(i->compiled[ctype]);
-                       i->compiled[ctype] = NULL;
-                       return talloc_asprintf(m,
-                                              "Dependency %s"
-                                              " did not build:\n%s",
-                                              m->basename, output);
-               }
-       }
-       return NULL;
-}
-
-char *build_submodule(struct manifest *m, const char *flags,
-                     enum compile_type ctype)
-{
-       char *errstr;
-
-       if (m->compiled[ctype])
-               return NULL;
-
-       if (!expect_obj_file(m))
-               return NULL;
-
-       if (verbose >= 2)
-               printf("  Building dependency %s\n", m->dir);
-
-       errstr = build_subdir_objs(m, flags, ctype);
-       if (errstr)
-               return errstr;
-
-       m->compiled[ctype] = build_module(m, false, ctype, &errstr);
-       if (!m->compiled[ctype])
-               return errstr;
-       return NULL;
-}
-
-static void check_depends_built(struct manifest *m,
-                               bool keep,
-                               unsigned int *timeleft, struct score *score)
-{
-       struct manifest *i;
-
-       list_for_each(&m->deps, i, list) {
-               char *errstr = build_submodule(i, cflags, COMPILE_NORMAL);
-
-               if (errstr) {
-                       score->error = talloc_asprintf(score,
-                                                      "Dependency %s"
-                                                      " did not build:\n%s",
-                                                      i->basename, errstr);
-                       return;
-               }
-       }
-
-       score->pass = true;
-       score->score = score->total;
-}
-
-struct ccanlint depends_build = {
-       .key = "depends_build",
-       .name = "Module's CCAN dependencies can be found or built",
-       .check = check_depends_built,
-       .can_run = can_build,
-       .needs = "depends_exist"
-};
-
-REGISTER_TEST(depends_build);
diff --git a/tools/ccanlint/compulsory_tests/main_header_compiles.c b/tools/ccanlint/compulsory_tests/main_header_compiles.c
deleted file mode 100644 (file)
index 99f3aa3..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <tools/ccanlint/ccanlint.h>
-#include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/grab_file/grab_file.h>
-#include <ccan/str/str.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <string.h>
-#include <ctype.h>
-
-static const char *can_build(struct manifest *m)
-{
-       if (safe_mode)
-               return "Safe mode enabled";
-       return NULL;
-}
-
-static struct ccan_file *main_header(struct manifest *m)
-{
-       struct ccan_file *f;
-
-       list_for_each(&m->h_files, f, list) {
-               if (strstarts(f->name, m->basename)
-                   && strlen(f->name) == strlen(m->basename) + 2)
-                       return f;
-       }
-       /* Should not happen: we depend on has_main_header */
-       abort();
-}
-
-static void check_includes_build(struct manifest *m,
-                                bool keep,
-                                unsigned int *timeleft, struct score *score)
-{
-       char *contents;
-       char *tmpsrc, *tmpobj, *cmdout;
-       int fd;
-       struct ccan_file *mainh = main_header(m);
-
-       tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
-       tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
-
-       fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
-       if (fd < 0)
-               err(1, "Creating temporary file %s", tmpsrc);
-
-       contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n",
-                                  m->basename, m->basename);
-       if (write(fd, contents, strlen(contents)) != strlen(contents))
-               err(1, "writing to temporary file %s", tmpsrc);
-       close(fd);
-
-       if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
-                          tmpobj, &cmdout)) {
-               score->pass = true;
-               score->score = score->total;
-       } else {
-               score->error = talloc_asprintf(score,
-                                      "#include of the main header file:\n%s",
-                                      cmdout);
-       }
-}
-
-struct ccanlint main_header_compiles = {
-       .key = "main_header_compiles",
-       .name = "Modules main header compiles",
-       .check = check_includes_build,
-       .can_run = can_build,
-       .needs = "depends_exist main_header_exists"
-};
-
-REGISTER_TEST(main_header_compiles);
diff --git a/tools/ccanlint/compulsory_tests/main_header_exists.c b/tools/ccanlint/compulsory_tests/main_header_exists.c
deleted file mode 100644 (file)
index 68ea135..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <tools/ccanlint/ccanlint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <ccan/str/str.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/noerr/noerr.h>
-
-static void check_has_main_header(struct manifest *m,
-                                 bool keep,
-                                 unsigned int *timeleft, struct score *score)
-{
-       struct ccan_file *f;
-
-       list_for_each(&m->h_files, f, list) {
-               if (strstarts(f->name, m->basename)
-                   && strlen(f->name) == strlen(m->basename) + 2) {
-                       score->pass = true;
-                       score->score = score->total;
-                       return;
-               } 
-       }
-       score->error = talloc_asprintf(score,
-       "You have no %s/%s.h header file.\n\n"
-       "CCAN modules have a name, the same as the directory name.  They're\n"
-       "expected to have an interface in the header of the same name.\n",
-                                      m->basename, m->basename);
-}
-
-struct ccanlint main_header_exists = {
-       .key = "main_header_exists",
-       .name = "Module has main header file",
-       .check = check_has_main_header,
-       .needs = ""
-};
-
-REGISTER_TEST(main_header_exists);
diff --git a/tools/ccanlint/compulsory_tests/module_links.c b/tools/ccanlint/compulsory_tests/module_links.c
deleted file mode 100644 (file)
index 0bf9821..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <tools/ccanlint/ccanlint.h>
-#include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/str/str.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <string.h>
-#include <ctype.h>
-
-static const char *can_build(struct manifest *m)
-{
-       if (safe_mode)
-               return "Safe mode enabled";
-       return NULL;
-}
-
-static char *obj_list(const struct manifest *m)
-{
-       char *list = talloc_strdup(m, "");
-       struct manifest *i;
-
-       /* Other CCAN deps. */
-       list_for_each(&m->deps, i, list) {
-               if (i->compiled[COMPILE_NORMAL])
-                       list = talloc_asprintf_append(list, "%s ",
-                                                     i->compiled
-                                                     [COMPILE_NORMAL]);
-       }
-       return list;
-}
-
-static char *lib_list(const struct manifest *m)
-{
-       unsigned int i, num;
-       char **libs = get_libs(m, ".",
-                              &num, &m->info_file->compiled[COMPILE_NORMAL]);
-       char *ret = talloc_strdup(m, "");
-
-       for (i = 0; i < num; i++)
-               ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
-       return ret;
-}
-
-static void check_use_build(struct manifest *m,
-                           bool keep,
-                           unsigned int *timeleft, struct score *score)
-{
-       char *contents;
-       char *tmpfile, *cmdout;
-       char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
-       int fd;
-
-       tmpfile = maybe_temp_file(m, ".c", keep, basename);
-
-       fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
-       if (fd < 0)
-               err(1, "Creating temporary file %s", tmpfile);
-
-       contents = talloc_asprintf(tmpfile,
-                                  "#include <ccan/%s/%s.h>\n"
-                                  "int main(void)\n"
-                                  "{\n"
-                                  "    return 0;\n"
-                                  "}\n",
-                                  m->basename, m->basename);
-       if (write(fd, contents, strlen(contents)) != strlen(contents))
-               err(1, "Failure writing to temporary file %s", tmpfile);
-       close(fd);
-
-       if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
-                            compiler, cflags, lib_list(m),
-                            maybe_temp_file(m, "", keep, tmpfile),
-                            &cmdout)) {
-               score->pass = true;
-               score->score = score->total;
-       } else {
-               score->error = cmdout;
-       }
-}
-
-struct ccanlint module_links = {
-       .key = "module_links",
-       .name = "Module can be linked against trivial program",
-       .check = check_use_build,
-       .can_run = can_build,
-       .needs = "module_builds depends_build"
-};
-
-REGISTER_TEST(module_links);
diff --git a/tools/ccanlint/tests/depends_build.c b/tools/ccanlint/tests/depends_build.c
new file mode 100644 (file)
index 0000000..e7faa1f
--- /dev/null
@@ -0,0 +1,109 @@
+#include <tools/ccanlint/ccanlint.h>
+#include <tools/tools.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/str/str.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+#include "../compulsory_tests/build.h"
+
+static const char *can_build(struct manifest *m)
+{
+       if (safe_mode)
+               return "Safe mode enabled";
+       return NULL;
+}
+
+static bool expect_obj_file(struct manifest *m)
+{
+       /* If it has C files, we expect an object file built from them. */
+       return !list_empty(&m->c_files);
+}
+
+static char *build_subdir_objs(struct manifest *m,
+                              const char *flags,
+                              enum compile_type ctype)
+{
+       struct ccan_file *i;
+
+       list_for_each(&m->c_files, i, list) {
+               char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
+               char *output;
+
+               i->compiled[ctype] = maybe_temp_file(m, "", false, fullfile);
+               if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
+                                   i->compiled[ctype], &output)) {
+                       talloc_free(i->compiled[ctype]);
+                       i->compiled[ctype] = NULL;
+                       return talloc_asprintf(m,
+                                              "Dependency %s"
+                                              " did not build:\n%s",
+                                              m->basename, output);
+               }
+       }
+       return NULL;
+}
+
+char *build_submodule(struct manifest *m, const char *flags,
+                     enum compile_type ctype)
+{
+       char *errstr;
+
+       if (m->compiled[ctype])
+               return NULL;
+
+       if (!expect_obj_file(m))
+               return NULL;
+
+       if (verbose >= 2)
+               printf("  Building dependency %s\n", m->dir);
+
+       errstr = build_subdir_objs(m, flags, ctype);
+       if (errstr)
+               return errstr;
+
+       m->compiled[ctype] = build_module(m, false, ctype, &errstr);
+       if (!m->compiled[ctype])
+               return errstr;
+       return NULL;
+}
+
+static void check_depends_built(struct manifest *m,
+                               bool keep,
+                               unsigned int *timeleft, struct score *score)
+{
+       struct manifest *i;
+
+       list_for_each(&m->deps, i, list) {
+               char *errstr = build_submodule(i, cflags, COMPILE_NORMAL);
+
+               if (errstr) {
+                       score->error = talloc_asprintf(score,
+                                                      "Dependency %s"
+                                                      " did not build:\n%s",
+                                                      i->basename, errstr);
+                       return;
+               }
+       }
+
+       score->pass = true;
+       score->score = score->total;
+}
+
+struct ccanlint depends_build = {
+       .key = "depends_build",
+       .name = "Module's CCAN dependencies can be found or built",
+       .check = check_depends_built,
+       .can_run = can_build,
+       .needs = "depends_exist"
+};
+
+REGISTER_TEST(depends_build);
diff --git a/tools/ccanlint/tests/main_header_compiles.c b/tools/ccanlint/tests/main_header_compiles.c
new file mode 100644 (file)
index 0000000..99f3aa3
--- /dev/null
@@ -0,0 +1,79 @@
+#include <tools/ccanlint/ccanlint.h>
+#include <tools/tools.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/grab_file/grab_file.h>
+#include <ccan/str/str.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+
+static const char *can_build(struct manifest *m)
+{
+       if (safe_mode)
+               return "Safe mode enabled";
+       return NULL;
+}
+
+static struct ccan_file *main_header(struct manifest *m)
+{
+       struct ccan_file *f;
+
+       list_for_each(&m->h_files, f, list) {
+               if (strstarts(f->name, m->basename)
+                   && strlen(f->name) == strlen(m->basename) + 2)
+                       return f;
+       }
+       /* Should not happen: we depend on has_main_header */
+       abort();
+}
+
+static void check_includes_build(struct manifest *m,
+                                bool keep,
+                                unsigned int *timeleft, struct score *score)
+{
+       char *contents;
+       char *tmpsrc, *tmpobj, *cmdout;
+       int fd;
+       struct ccan_file *mainh = main_header(m);
+
+       tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
+       tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
+
+       fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
+       if (fd < 0)
+               err(1, "Creating temporary file %s", tmpsrc);
+
+       contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n",
+                                  m->basename, m->basename);
+       if (write(fd, contents, strlen(contents)) != strlen(contents))
+               err(1, "writing to temporary file %s", tmpsrc);
+       close(fd);
+
+       if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
+                          tmpobj, &cmdout)) {
+               score->pass = true;
+               score->score = score->total;
+       } else {
+               score->error = talloc_asprintf(score,
+                                      "#include of the main header file:\n%s",
+                                      cmdout);
+       }
+}
+
+struct ccanlint main_header_compiles = {
+       .key = "main_header_compiles",
+       .name = "Modules main header compiles",
+       .check = check_includes_build,
+       .can_run = can_build,
+       .needs = "depends_exist main_header_exists"
+};
+
+REGISTER_TEST(main_header_compiles);
diff --git a/tools/ccanlint/tests/main_header_exists.c b/tools/ccanlint/tests/main_header_exists.c
new file mode 100644 (file)
index 0000000..b6150dc
--- /dev/null
@@ -0,0 +1,43 @@
+#include <tools/ccanlint/ccanlint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <ccan/str/str.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/noerr/noerr.h>
+
+static void check_has_main_header(struct manifest *m,
+                                 bool keep,
+                                 unsigned int *timeleft, struct score *score)
+{
+       struct ccan_file *f;
+
+       list_for_each(&m->h_files, f, list) {
+               if (strstarts(f->name, m->basename)
+                   && strlen(f->name) == strlen(m->basename) + 2) {
+                       score->pass = true;
+                       score->score = score->total;
+                       return;
+               }
+       }
+       score->error = talloc_asprintf(score,
+       "You have no %s/%s.h header file.\n\n"
+       "CCAN modules have a name, the same as the directory name.  They're\n"
+       "expected to have an interface in the header of the same name.\n",
+                                      m->basename, m->basename);
+}
+
+struct ccanlint main_header_exists = {
+       .key = "main_header_exists",
+       .name = "Module has main header file",
+       .check = check_has_main_header,
+       .needs = ""
+};
+
+REGISTER_TEST(main_header_exists);
diff --git a/tools/ccanlint/tests/module_links.c b/tools/ccanlint/tests/module_links.c
new file mode 100644 (file)
index 0000000..0bf9821
--- /dev/null
@@ -0,0 +1,96 @@
+#include <tools/ccanlint/ccanlint.h>
+#include <tools/tools.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/str/str.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+
+static const char *can_build(struct manifest *m)
+{
+       if (safe_mode)
+               return "Safe mode enabled";
+       return NULL;
+}
+
+static char *obj_list(const struct manifest *m)
+{
+       char *list = talloc_strdup(m, "");
+       struct manifest *i;
+
+       /* Other CCAN deps. */
+       list_for_each(&m->deps, i, list) {
+               if (i->compiled[COMPILE_NORMAL])
+                       list = talloc_asprintf_append(list, "%s ",
+                                                     i->compiled
+                                                     [COMPILE_NORMAL]);
+       }
+       return list;
+}
+
+static char *lib_list(const struct manifest *m)
+{
+       unsigned int i, num;
+       char **libs = get_libs(m, ".",
+                              &num, &m->info_file->compiled[COMPILE_NORMAL]);
+       char *ret = talloc_strdup(m, "");
+
+       for (i = 0; i < num; i++)
+               ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
+       return ret;
+}
+
+static void check_use_build(struct manifest *m,
+                           bool keep,
+                           unsigned int *timeleft, struct score *score)
+{
+       char *contents;
+       char *tmpfile, *cmdout;
+       char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
+       int fd;
+
+       tmpfile = maybe_temp_file(m, ".c", keep, basename);
+
+       fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
+       if (fd < 0)
+               err(1, "Creating temporary file %s", tmpfile);
+
+       contents = talloc_asprintf(tmpfile,
+                                  "#include <ccan/%s/%s.h>\n"
+                                  "int main(void)\n"
+                                  "{\n"
+                                  "    return 0;\n"
+                                  "}\n",
+                                  m->basename, m->basename);
+       if (write(fd, contents, strlen(contents)) != strlen(contents))
+               err(1, "Failure writing to temporary file %s", tmpfile);
+       close(fd);
+
+       if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
+                            compiler, cflags, lib_list(m),
+                            maybe_temp_file(m, "", keep, tmpfile),
+                            &cmdout)) {
+               score->pass = true;
+               score->score = score->total;
+       } else {
+               score->error = cmdout;
+       }
+}
+
+struct ccanlint module_links = {
+       .key = "module_links",
+       .name = "Module can be linked against trivial program",
+       .check = check_use_build,
+       .can_run = can_build,
+       .needs = "module_builds depends_build"
+};
+
+REGISTER_TEST(module_links);