tests: use assert instead of plain abort.

* tests/actions.at, tests/calc.at, tests/conflicts.at,
* tests/cxx-type.at, tests/glr-regression.at, tests/input.at,
* tests/named-refs.at, tests/regression.at, tests/torture.at,
* tests/local.at:
Prefer assert to abort.
This commit is contained in:
Akim Demaille
2012-06-26 10:20:35 +02:00
parent 0e16927b48
commit 77519a7d18
10 changed files with 51 additions and 62 deletions

View File

@@ -324,8 +324,7 @@ static
AT_LOC.last_line = AT_LOC.last_column = AT_LOC.first_line + 9; AT_LOC.last_line = AT_LOC.last_column = AT_LOC.first_line + 9;
])[ ])[
if (! (0 <= c && c <= strlen (source))) assert (0 <= c && c <= strlen (source));
abort ();
if (source[c]) if (source[c])
printf ("sending: '%c'", source[c]); printf ("sending: '%c'", source[c]);
else else

View File

@@ -45,7 +45,7 @@ m4_define([_AT_DATA_CALC_Y],
[m4_fatal([$0: Invalid arguments: $@])])dnl [m4_fatal([$0: Invalid arguments: $@])])dnl
m4_pushdef([AT_CALC_MAIN], m4_pushdef([AT_CALC_MAIN],
[#include <stdlib.h> /* abort */ [#include <assert.h>
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#else #else
@@ -98,10 +98,8 @@ main (int argc, const char **argv)
status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[); status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[);
if (fclose (input)) if (fclose (input))
perror ("fclose"); perror ("fclose");
if (global_result != result) assert (global_result == result);
abort (); assert (global_count == count);
if (global_count != count)
abort ();
return status; return status;
} }
]]) ]])

View File

@@ -57,6 +57,7 @@ AT_DATA_GRAMMAR([input.y],
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#define YYERROR_VERBOSE 1 #define YYERROR_VERBOSE 1
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
@@ -67,8 +68,7 @@ static int
yylex (void) yylex (void)
{ {
static size_t toknum; static size_t toknum;
if (! (toknum <= strlen (input))) assert (toknum <= strlen (input));
abort ();
return input[toknum++]; return input[toknum++];
} }

View File

@@ -122,12 +122,12 @@ declarator : ID
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
if (argc != 2) assert (argc == 2);
abort ();
if (!freopen (argv[1], "r", stdin)) if (!freopen (argv[1], "r", stdin))
return 3; return 3;
return yyparse (); return yyparse ();
@@ -152,8 +152,7 @@ main (int argc, char **argv)
while (1) while (1)
{ {
if (feof (stdin)) assert (!feof (stdin));
abort ();
c = getchar (); c = getchar ();
switch (c) switch (c)
{ {
@@ -182,8 +181,7 @@ main (int argc, char **argv)
{ {
buffer[i++] = c; buffer[i++] = c;
colNum += 1; colNum += 1;
if (i == sizeof buffer - 1) assert (i != sizeof buffer - 1);
abort ();
c = getchar (); c = getchar ();
} }
while (isalnum (c) || c == '_'); while (isalnum (c) || c == '_');

View File

@@ -32,6 +32,7 @@ AT_DATA_GRAMMAR([glr-regr1.y],
%{ %{
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#define YYSTYPE int #define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1); static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
@@ -80,8 +81,7 @@ yylex (void)
for (;;) for (;;)
{ {
int ch; int ch;
if (feof (stdin)) assert (!feof (stdin));
abort ();
ch = getchar (); ch = getchar ();
if (ch == EOF) if (ch == EOF)
return 0; return 0;
@@ -128,6 +128,7 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
%} %}
@@ -177,8 +178,7 @@ yylex (void)
{ {
char buf[50]; char buf[50];
char *s; char *s;
if (feof (stdin)) assert (!feof (stdin));
abort ();
switch (fscanf (input, " %1[a-z,]", buf)) switch (fscanf (input, " %1[a-z,]", buf))
{ {
case 1: case 1:
@@ -190,8 +190,7 @@ yylex (void)
} }
if (fscanf (input, "%49s", buf) != 1) if (fscanf (input, "%49s", buf) != 1)
return 0; return 0;
if (sizeof buf - 1 <= strlen (buf)) assert (strlen (buf) < sizeof buf - 1);
abort ();
s = (char *) malloc (strlen (buf) + 1); s = (char *) malloc (strlen (buf) + 1);
strcpy (s, buf); strcpy (s, buf);
yylval = s; yylval = s;
@@ -242,6 +241,7 @@ AT_DATA_GRAMMAR([glr-regr3.y],
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
static int MergeRule (int x0, int x1); static int MergeRule (int x0, int x1);
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
@@ -302,8 +302,7 @@ int T[] = { T1, T2, T3, T4 };
int yylex (void) int yylex (void)
{ {
char inp[3]; char inp[3];
if (feof (stdin)) assert (!feof (stdin));
abort ();
if (fscanf (input, "%2s", inp) == EOF) if (fscanf (input, "%2s", inp) == EOF)
return 0; return 0;
switch (inp[0]) switch (inp[0])
@@ -935,6 +934,7 @@ AT_DATA_GRAMMAR([glr-regr12.y],
%{ %{
# include <stdlib.h> # include <stdlib.h>
# include <assert.h>
static int merge (YYSTYPE, YYSTYPE); static int merge (YYSTYPE, YYSTYPE);
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
@@ -1003,8 +1003,7 @@ yylex (void)
{ {
static int const input[] = { PARENT_RHS_AFTER, 0 }; static int const input[] = { PARENT_RHS_AFTER, 0 };
static size_t toknum; static size_t toknum;
if (! (toknum < sizeof input / sizeof *input)) assert (toknum < sizeof input / sizeof *input);
abort ();
if (input[toknum] == PARENT_RHS_AFTER) if (input[toknum] == PARENT_RHS_AFTER)
parent_rhs_after_value = 1; parent_rhs_after_value = 1;
return input[toknum++]; return input[toknum++];
@@ -1064,6 +1063,7 @@ AT_DATA_GRAMMAR([glr-regr13.y],
%{ %{
#include <stdio.h> #include <stdio.h>
#include <assert.h>
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
static void print_lookahead (char const *); static void print_lookahead (char const *);
@@ -1122,8 +1122,7 @@ yylex (void)
{ {
static char const input[] = "ab"; static char const input[] = "ab";
static size_t toknum; static size_t toknum;
if (! (toknum < sizeof input)) assert (toknum < sizeof input);
abort ();
yylloc.first_line = yylloc.last_line = 1; yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1; yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a'; yylval.value = input[toknum] + 'A' - 'a';
@@ -1212,6 +1211,7 @@ AT_DATA_GRAMMAR([glr-regr14.y],
%{ %{
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
static void print_lookahead (char const *); static void print_lookahead (char const *);
@@ -1328,8 +1328,7 @@ yylex (void)
{ {
static char const input[] = "abcdddd"; static char const input[] = "abcdddd";
static size_t toknum; static size_t toknum;
if (! (toknum < sizeof input)) assert (toknum < sizeof input);
abort ();
yylloc.first_line = yylloc.last_line = 1; yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1; yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a'; yylval.value = input[toknum] + 'A' - 'a';
@@ -1492,6 +1491,7 @@ AT_DATA_GRAMMAR([glr-regr16.y],
%{ %{
# include <stdlib.h> # include <stdlib.h>
# include <assert.h>
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
static int lookahead_value = 0; static int lookahead_value = 0;
@@ -1512,8 +1512,7 @@ yylex (void)
{ {
static char const input[] = "ab"; static char const input[] = "ab";
static size_t toknum; static size_t toknum;
if (! (toknum < sizeof input)) assert (toknum < sizeof input);
abort ();
if (input[toknum] == 'b') if (input[toknum] == 'b')
lookahead_value = 1; lookahead_value = 1;
return input[toknum++]; return input[toknum++];
@@ -1593,6 +1592,7 @@ empty1: ;
empty2: ; empty2: ;
%% %%
# include <assert.h>
static void static void
yyerror (YYLTYPE *locp, char const *msg) yyerror (YYLTYPE *locp, char const *msg)
@@ -1606,8 +1606,7 @@ yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
{ {
static char const input[] = "ab"; static char const input[] = "ab";
static size_t toknum; static size_t toknum;
if (! (toknum < sizeof input)) assert (toknum < sizeof input);
abort ();
lvalp->dummy = 0; lvalp->dummy = 0;
llocp->first_line = llocp->last_line = 2; llocp->first_line = llocp->last_line = 2;
llocp->first_column = toknum + 1; llocp->first_column = toknum + 1;

View File

@@ -442,6 +442,7 @@ char apostrophe = '\'';
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
%} %}
/* %{ and %} can be here too. */ /* %{ and %} can be here too. */
@@ -509,8 +510,7 @@ yylex (void)
#output "; /* " #output "; /* "
*/ */
static size_t toknum; static size_t toknum;
if (! (toknum < sizeof input)) assert (toknum < sizeof input);
abort ();
yylval = value_as_yystype (input[toknum]); yylval = value_as_yystype (input[toknum]);
return input[toknum++]; return input[toknum++];
} }

View File

@@ -304,7 +304,7 @@ m4_define([AT_YYLEX_DECLARE],
]) ])
m4_define([AT_YYLEX_DEFINE], m4_define([AT_YYLEX_DEFINE],
[[#include <stdlib.h> /* abort */ [[#include <assert.h>
static static
]AT_YYLEX_PROTOTYPE[ ]AT_YYLEX_PROTOTYPE[
{ {
@@ -312,8 +312,7 @@ static
static size_t toknum = 0; static size_t toknum = 0;
int res; int res;
]AT_USE_LEX_ARGS[; ]AT_USE_LEX_ARGS[;
if (! (toknum < sizeof input)) assert (toknum < sizeof input);
abort ();
res = input[toknum++]; res = input[toknum++];
]$2[;]AT_LOCATION_IF([[ ]$2[;]AT_LOCATION_IF([[
]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1; ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;

View File

@@ -162,10 +162,8 @@ int main (int argc, const char **argv)
} }
status = yyparse (); status = yyparse ();
fclose (input); fclose (input);
if (global_result != result) assert (global_result == result);
abort (); assert (global_count == count);
if (global_count != count)
abort ();
return status; return status;
} }
]]) ]])

View File

@@ -910,6 +910,7 @@ yyparse ()
} }
]) ])
#include <assert.h>
static int static int
yylex (AT_LALR1_CC_IF([int *lval], [void])) yylex (AT_LALR1_CC_IF([int *lval], [void]))
[{ [{
@@ -919,8 +920,7 @@ yylex (AT_LALR1_CC_IF([int *lval], [void]))
}; };
static size_t toknum; static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
if (! (toknum < sizeof tokens / sizeof *tokens)) assert (toknum < sizeof tokens / sizeof *tokens);
abort ();
return tokens[toknum++]; return tokens[toknum++];
}] }]
@@ -995,6 +995,7 @@ yyparse ()
} }
])[ ])[
#include <assert.h>
static int static int
yylex (]AT_LALR1_CC_IF([int *lval], [void])[) yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
{ {
@@ -1004,8 +1005,7 @@ yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
}; };
static size_t toknum; static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
if (! (toknum < sizeof tokens / sizeof *tokens)) assert (toknum < sizeof tokens / sizeof *tokens);
abort ();
return tokens[toknum++]; return tokens[toknum++];
} }

View File

@@ -56,6 +56,7 @@ print <<EOF;
%{ %{
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#define MAX $max #define MAX $max
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
@@ -77,8 +78,8 @@ for my $size (1 .. $max)
print <<EOF; print <<EOF;
%% %%
input: input:
exp { if (\@S|@1 != 0) abort (); \$\$ = \@S|@1; } exp { assert (\@S|@1 == 0); \$\$ = \@S|@1; }
| input exp { if (\@S|@2 != \@S|@1 + 1) abort (); \$\$ = \@S|@2; } | input exp { assert (\@S|@2 == \@S|@1 + 1); \$\$ = \@S|@2; }
; ;
exp: exp:
@@ -192,6 +193,7 @@ print
print <<\EOF; print <<\EOF;
%% %%
#include <assert.h>
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
static int static int
yylex (void) yylex (void)
@@ -199,8 +201,7 @@ yylex (void)
static int counter = 1; static int counter = 1;
if (counter <= MAX) if (counter <= MAX)
return counter++; return counter++;
if (counter++ != MAX + 1) assert (counter++ == MAX + 1);
abort ();
return 0; return 0;
} }
@@ -328,8 +329,7 @@ yylex (void)
static int counter = 1; static int counter = 1;
if (counter > MAX) if (counter > MAX)
{ {
if (counter++ != MAX + 1) assert (counter++ == MAX + 1);
abort ();
return 0; return 0;
} }
if (return_token) if (return_token)
@@ -401,11 +401,11 @@ AT_DATA([input.y],
exp: WAIT_FOR_EOF exp | ; exp: WAIT_FOR_EOF exp | ;
%% %%
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
#include <assert.h>
static int static int
yylex (void) yylex (void)
{ {
if (yylval < 0) assert (0 <= yylval);
abort ();
if (yylval--) if (yylval--)
return WAIT_FOR_EOF; return WAIT_FOR_EOF;
else else
@@ -417,13 +417,12 @@ main (int argc, const char **argv)
{ {
char *endp; char *endp;
YYSTYPE yylval_init; YYSTYPE yylval_init;
if (argc != 2) assert (argc == 2);
abort ();
yylval_init = strtol (argv[1], &endp, 10); yylval_init = strtol (argv[1], &endp, 10);
if (! (argv[1] != endp assert (argv[1] != endp);
&& 0 <= yylval_init && yylval_init <= INT_MAX assert (0 <= yylval_init);
&& errno != ERANGE)) assert (yylval_init <= INT_MAX);
abort (); assert (errno != ERANGE);
yydebug = 1; yydebug = 1;
{ {
int count; int count;
@@ -438,8 +437,7 @@ main (int argc, const char **argv)
[[ new_status = yypull_parse (ps); [[ new_status = yypull_parse (ps);
]], ]],
[[ new_status = yyparse (); [[ new_status = yyparse ();
]])[ if (count > 0 && new_status != status) ]])[ assert (0 <= count || new_status == status);
abort ();
status = new_status; status = new_status;
} }
]m4_bmatch([$2], [%push-], ]m4_bmatch([$2], [%push-],