1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5 #include <ccan/str_talloc/str_talloc.h>
6 #include <ccan/foreach/foreach.h>
19 static void check_hash_if(struct manifest *m,
21 unsigned int *timeleft, struct score *score)
23 struct list_head *list;
24 const char *explanation =
25 "\n\t(#if works like #ifdef, but with gcc's -Wundef, we can detect\n"
26 "\tmistyped or unknown configuration options)";
28 foreach_ptr(list, &m->c_files, &m->h_files,
29 &m->run_tests, &m->api_tests,
30 &m->compile_ok_tests, &m->compile_fail_tests,
31 &m->other_test_c_files) {
34 list_for_each(list, f, list) {
36 char **lines = get_ccan_file_lines(f);
38 for (i = 0; lines[i]; i++) {
39 const char *line = lines[i];
42 if (!get_token(&line, "#"))
44 if (!(get_token(&line, "if")
45 && get_token(&line, "defined")
46 && get_token(&line, "("))
47 && !get_token(&line, "ifdef"))
50 sym = get_symbol_token(lines, &line);
51 if (!sym || !strstarts(sym, "HAVE_"))
53 score_file_error(score, f, i+1,
54 "%s should be tested with #if"
64 score->score = score->total;
68 struct ccanlint hash_if = {
70 .name = "Features are checked with #if not #ifdef",
71 .check = check_hash_if,
75 REGISTER_TEST(hash_if);