3 #include <ccan/list/list.h>
5 #include "../doc_extract.h"
7 #define REGISTER_TEST(name, ...) extern struct ccanlint name
8 #include "generated-compulsory-tests"
9 #include "generated-normal-tests"
12 #define REGISTER_TEST(name, ...)
14 /* 0 == Describe failed tests.
15 1 == Describe results for partial failures.
16 2 == One line per test, plus details of failures.
18 Mainly for debugging ccanlint:
19 3 == Describe every object built.
20 4 == Describe every action. */
25 /* The module name, ie. final element of dir name */
27 struct ccan_file *info_file;
29 /* Linked off deps. */
30 struct list_node list;
31 /* Where our final compiled output is */
34 struct list_head c_files;
35 struct list_head h_files;
37 struct list_head run_tests;
38 struct list_head api_tests;
39 struct list_head compile_ok_tests;
40 struct list_head compile_fail_tests;
41 struct list_head other_test_c_files;
42 struct list_head other_test_files;
44 struct list_head other_files;
45 struct list_head examples;
46 struct list_head mangled_examples;
48 /* From tests/check_depends_exist.c */
49 struct list_head deps;
52 struct manifest *get_manifest(const void *ctx, const char *dir);
55 struct list_node list;
56 struct ccan_file *file;
57 unsigned int line; /* 0 not to print */
63 unsigned int score, total;
65 struct list_head per_file_errors;
69 struct list_node list;
71 /* More concise unique name of test. */
74 /* Unique name of test */
77 /* Can we run this test? Return string explaining why, if not. */
78 const char *(*can_run)(struct manifest *m);
80 /* keep is set if you should keep the results.
81 * If timeleft is set to 0, means it timed out.
82 * score is the result, and a talloc context freed after all our
83 * depends are done. */
84 void (*check)(struct manifest *m,
85 bool keep, unsigned int *timeleft, struct score *score);
87 /* Can we do something about it? (NULL if not) */
88 void (*handle)(struct manifest *m, struct score *score);
90 /* Options from _info. */
92 /* If not set, we'll give an error if they try to set options. */
95 /* Internal use fields: */
96 /* Who depends on us? */
97 struct list_head dependencies;
98 /* How many things do we (still) depend on? */
99 unsigned int num_depends;
100 /* Did we skip a dependency? If so, must skip this, too. */
102 /* Did we fail a dependency? If so, skip and mark as fail. */
104 /* Did the user want to keep these results? */
108 /* Ask the user a yes/no question: the answer is NO if there's an error. */
109 bool ask(const char *question);
111 enum line_info_type {
112 PREPROC_LINE, /* Line starts with # */
113 CODE_LINE, /* Code (ie. not pure comment). */
114 DOC_LINE, /* Line with kernel-doc-style comment. */
115 COMMENT_LINE, /* (pure) comment line */
118 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
119 * and #if <SYMBOL>/#if !<SYMBOL> */
120 struct pp_conditions {
121 /* We're inside another ifdef? */
122 struct pp_conditions *parent;
134 /* Preprocessor information about each line. */
136 enum line_info_type type;
138 /* Is this actually a continuation of line above? (which ends in \) */
141 /* Conditions for this line to be compiled. */
142 struct pp_conditions *cond;
146 struct list_node list;
148 /* Name (usually, within m->dir). */
151 /* Full path name. */
154 /* Pristine version of the original file.
155 * Use get_ccan_file_contents to fill this. */
156 const char *contents;
157 size_t contents_size;
159 /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
160 unsigned int num_lines;
162 struct line_info *line_info;
164 struct list_head *doc_sections;
166 /* If this file gets compiled (eg. .C file to .o file), result here. */
169 /* Compiled with coverage information. */
173 /* A new ccan_file, with the given name (talloc_steal onto returned value). */
174 struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
176 /* Use this rather than accessing f->contents directly: loads on demand. */
177 const char *get_ccan_file_contents(struct ccan_file *f);
179 /* Use this rather than accessing f->lines directly: loads on demand. */
180 char **get_ccan_file_lines(struct ccan_file *f);
182 /* Use this rather than accessing f->lines directly: loads on demand. */
183 struct line_info *get_ccan_line_info(struct ccan_file *f);
191 /* Simple evaluator. If symbols are set this way, is this condition true?
192 * NULL values mean undefined, NULL symbol terminates. */
193 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
195 const unsigned int *value, ...);
197 /* Get token if it's equal to token. */
198 bool get_token(const char **line, const char *token);
199 /* Talloc copy of symbol token, or NULL. Increment line. */
200 char *get_symbol_token(void *ctx, const char **line);
202 /* Similarly for ->doc_sections */
203 struct list_head *get_ccan_file_docs(struct ccan_file *f);
205 /* Add an error about this file (and line, if non-zero) to the score struct */
206 void score_file_error(struct score *, struct ccan_file *f, unsigned line,
210 extern struct ccanlint trailing_whitespace;
214 struct list_node node;
215 struct ccanlint *dependent;
218 /* Are we happy to compile stuff, or just non-intrusive tests? */
219 extern bool safe_mode;
221 /* Where is the ccan dir? Available after first manifest. */
222 extern const char *ccan_dir;
224 #endif /* CCAN_LINT_H */