1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
4 #include <ccan/foreach/foreach.h>
17 static void check_hash_if(struct manifest *m,
18 unsigned int *timeleft UNNEEDED,
21 struct list_head *list;
22 const char *explanation =
23 "\n\t(#if works like #ifdef, but with gcc's -Wundef, we can detect\n"
24 "\tmistyped or unknown configuration options)";
26 /* We don't fail ccanlint for this. */
29 foreach_ptr(list, &m->c_files, &m->h_files,
30 &m->run_tests, &m->api_tests,
31 &m->compile_ok_tests, &m->compile_fail_tests,
32 &m->other_test_c_files) {
35 list_for_each(list, f, list) {
37 char **lines = get_ccan_file_lines(f);
39 for (i = 0; lines[i]; i++) {
40 const char *line = lines[i];
43 if (!get_token(&line, "#"))
45 if (!(get_token(&line, "if")
46 && get_token(&line, "defined")
47 && get_token(&line, "("))
48 && !get_token(&line, "ifdef"))
51 sym = get_symbol_token(lines, &line);
52 if (!sym || !strstarts(sym, "HAVE_"))
54 score_file_error(score, f, i+1,
55 "%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,
72 .needs = "info_exists"
75 REGISTER_TEST(hash_if);