Browse Source

ccanlint: add #line directives to examples.

This means error messages come out in the right place.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell 13 years ago
parent
commit
509fc838de
2 changed files with 8 additions and 2 deletions
  1. 2 1
      tools/ccanlint/tests/examples_compile.c
  2. 6 1
      tools/ccanlint/tests/examples_exist.c

+ 2 - 1
tools/ccanlint/tests/examples_compile.c

@@ -204,7 +204,8 @@ static bool looks_internal(char **lines, char **why)
 		const char *line = lines[i] + strspn(lines[i], " \t");
 		unsigned len = strspn(line, IDENT_CHARS);
 
-		if (!line[0] || cisspace(line[0]) || strstarts(line, "//"))
+		if (!line[0] || cisspace(line[0]) || strstarts(line, "//")
+		    || strstarts(line, "#line"))
 			continue;
 
 		assert(line[strlen(line)-1] != '\n');

+ 6 - 1
tools/ccanlint/tests/examples_exist.c

@@ -19,7 +19,7 @@
 static char *add_example(struct manifest *m, struct ccan_file *source,
 			 struct doc_section *example)
 {
-	char *name;
+	char *name, *linemarker;
 	unsigned int i;
 	int fd;
 	struct ccan_file *f;
@@ -43,6 +43,11 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
 		return talloc_asprintf(m, "Creating temporary file %s: %s",
 				       f->fullname, strerror(errno));
 
+	/* Add #line to demark where we are from, so errors are correct! */
+	linemarker = talloc_asprintf(f, "#line %i \"%s\"\n",
+				     example->srcline+2, source->fullname);
+	write(fd, linemarker, strlen(linemarker));
+
 	for (i = 0; i < example->num_lines; i++) {
 		if (write(fd, example->lines[i], strlen(example->lines[i]))
 		    != strlen(example->lines[i])