From 2d2897f4267340fa82ece21bada94f77be7e8f7c Mon Sep 17 00:00:00 2001 From: Steve Beattie Date: Fri, 25 Jun 2010 12:43:48 -0700 Subject: [PATCH] This patch adds a couple of additional lineno reporting testcases: * a non-include related syntax error (errors/modefail.sd) * multiple successful includes followed by a failed include (errors/multi_include.sd) It also fixes two issues with the parser's line counting: * the count began at 0 (demonstrated by the first testcase's error being reporting on one line less than it should be), and * an extra line increment when includes were detected (demonstrated by the second testcase's error being reported at a line beyond the correct linenumber. The existing testcases did not catch these because they were all based on the first include in the file failing and so the start of the count from 0 counteracted the extra counted line. --- parser/parser_include.c | 2 +- parser/parser_lex.l | 3 +-- parser/tst/Makefile | 4 ++++ parser/tst/errors/modefail.sd | 7 +++++++ parser/tst/errors/multi_include.sd | 13 +++++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 parser/tst/errors/modefail.sd create mode 100644 parser/tst/errors/multi_include.sd diff --git a/parser/parser_include.c b/parser/parser_include.c index 8a6659194..9a1abe1a1 100644 --- a/parser/parser_include.c +++ b/parser/parser_include.c @@ -284,7 +284,7 @@ static void start_include_position(char *filename) if (current_filename) free(current_filename); current_filename = strdup(filename ? filename : "stdin"); - current_lineno = 0; + current_lineno = 1; } void push_include_stack(char *filename) diff --git a/parser/parser_lex.l b/parser/parser_lex.l index 87dfe3974..5034bd4cd 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -49,7 +49,7 @@ #endif #define NPDEBUG(fmt, args...) /* Do nothing */ -int current_lineno = 0; +int current_lineno = 1; char *current_filename = NULL; struct ignored_suffix_t { @@ -427,7 +427,6 @@ LT_EQUAL <= #include/.*\r?\n { /* include */ PDEBUG("Matched #include\n"); - current_lineno++; BEGIN(INCLUDE); } diff --git a/parser/tst/Makefile b/parser/tst/Makefile index de2c315ff..0fffe582b 100644 --- a/parser/tst/Makefile +++ b/parser/tst/Makefile @@ -20,6 +20,10 @@ error_output: $(PARSER) grep -q "AppArmor parser error for errors/single.sd in errors/single.sd at line 3: Could not open 'failure'" LANG=C $(PARSER) -S -I errors 2>&1 >/dev/null errors/double.sd | \ grep -q "AppArmor parser error for errors/double.sd in errors/includes/busted at line 67: Could not open 'does-not-exist'" + LANG=C $(PARSER) -S -I errors 2>&1 >/dev/null errors/modefail.sd | \ + grep -q "AppArmor parser error for errors/modefail.sd in errors/modefail.sd at line 6: syntax error" + LANG=C $(PARSER) -S -I errors 2>&1 >/dev/null errors/multi_include.sd | \ + grep -q "AppArmor parser error for errors/multi_include.sd in errors/multi_include.sd at line 12: Could not open 'failure'" @echo "Error Output: PASS" parser_sanity: $(PARSER) diff --git a/parser/tst/errors/modefail.sd b/parser/tst/errors/modefail.sd new file mode 100644 index 000000000..21280c228 --- /dev/null +++ b/parser/tst/errors/modefail.sd @@ -0,0 +1,7 @@ +# 1 +# 2 +# 3 +/does/not/exist { # 4 + /lib/lib*.so rm, # 5 + /fail abcdefgh, # 6 +} # 7 diff --git a/parser/tst/errors/multi_include.sd b/parser/tst/errors/multi_include.sd new file mode 100644 index 000000000..9eb4b5b26 --- /dev/null +++ b/parser/tst/errors/multi_include.sd @@ -0,0 +1,13 @@ +# +# +# +/does/not/exist { + #include + #include + #include + #include + + /bin/true rix, + + #include +}