Skip to content

Commit

Permalink
Extract correct line numbers to use in line number test
Browse files Browse the repository at this point in the history
This makes the test much less fragile as now all that is need is for
@line@ and __LINE__ to be on the same line (the comment gets substituted
too, but it's a comment...)
  • Loading branch information
taniwha committed Nov 16, 2023
1 parent 02f1adf commit 0ff4ca2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ lexcompat*
!lexcompat.rules
!lexcompat.txt
lineno*
!lineno_generated.l
!lineno_generated.l.in
!lineno.rules
!lineno.txt
mem_nr
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ include_by_buffer_direct_SOURCES = include_by_buffer.direct.l
include_by_push_direct_SOURCES = include_by_push.direct.l
include_by_reentrant_direct_SOURCES = include_by_reentrant.direct.l
lineno_generated_SOURCES = lineno_generated.l
lineno_generated.l: lineno_generated.l.in
grep -n '@LINE@' $^ | sed -e 's%^\([0-9]\+\):.*%\1s/@LINE@/\1/%' | sed -f - $^ > $@.t && mv $@.t $@
mem_nr_SOURCES = mem_nr.l
mem_r_SOURCES = mem_r.l
mem_c99_SOURCES = mem_c99.l
Expand Down
17 changes: 9 additions & 8 deletions tests/lineno_generated.l → tests/lineno_generated.l.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@
%{
/* Test generated line numbers. Be careful editing this file
as it's all about ensuring flex generates correct line
directives.
directives, so the @LINE@ markers must be on the same line as a
their corresponding __LINE__ macros.
*/
#include <stdio.h>
#include "config.h"

static int defs_percent_expect = 32, defs_percent_got = __LINE__;
static int defs_percent_expect = @LINE@, defs_percent_got = __LINE__;
static int error_count = 0;

static void test_line (const char *desc, int expect, int got);

%}

static int defs_indent_expect = 39, defs_indent_got = __LINE__;
static int defs_indent_expect = @LINE@, defs_indent_got = __LINE__;

%option nounput noyywrap noinput
%option warn

%%
test_line ("prolog indent", 45, __LINE__);
test_line ("prolog indent", @LINE@, __LINE__);
%{
test_line ("prolog percent", 47, __LINE__);
test_line ("prolog percent", @LINE@, __LINE__);
%}
\n { test_line ("rules braced", 49, __LINE__); }
. test_line ("rules bare", 50, __LINE__);
\n { test_line ("rules braced", @LINE@, __LINE__); }
. test_line ("rules bare", @LINE@, __LINE__);

%%

Expand All @@ -66,7 +67,7 @@ main (void)
yy_delete_buffer (buffer);
test_line ("defs percent", defs_percent_expect, defs_percent_got);
test_line ("defs indent", defs_indent_expect, defs_indent_got);
test_line ("user code", 69, __LINE__);
test_line ("user code", @LINE@, __LINE__);

return error_count != 0;
}

0 comments on commit 0ff4ca2

Please sign in to comment.