Skip to content

Commit 25b3d0e

Browse files
committed
cex: check -Dcex.timeout
* src/counterexample.c (counterexample_init): Remove stray debug trace. Complain about invalid values. * tests/input.at (-Dcex.timeout): New.
1 parent de3041b commit 25b3d0e

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/counterexample.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <gl_rbtreehash_list.h>
3131
#include <hash.h>
3232
#include <mbswidth.h>
33+
#include <quote.h>
3334
#include <stdlib.h>
3435
#include <textstyle.h>
3536
#include <time.h>
@@ -1209,15 +1210,23 @@ static xtime_t cumulative_time;
12091210
void
12101211
counterexample_init (void)
12111212
{
1213+
// Check cex.timeout.
12121214
{
1213-
char *cp = muscle_percent_define_get ("cex.timeout");
1215+
const char *variable = "cex.timeout";
1216+
char *cp = muscle_percent_define_get (variable);
12141217
if (*cp != '\0')
12151218
{
12161219
char *end = NULL;
12171220
double v = c_strtod (cp, &end);
1218-
if (*end == '\0' && errno == 0)
1221+
if (*end == '\0' && errno == 0 && v >= 0)
12191222
time_limit = v;
1220-
fprintf (stderr, "lim: %f from %s\n", time_limit, cp);
1223+
else
1224+
{
1225+
location loc = muscle_percent_define_get_loc (variable);
1226+
complain (&loc, complaint,
1227+
_("invalid value for %%define variable %s: %s"),
1228+
quote (variable), quote_n (1, cp));
1229+
}
12211230
}
12221231
free (cp);
12231232
}

tests/input.at

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,3 +3283,39 @@ AT_TEST([-M foo= -M baz], [baz], [<command line>:6])
32833283
m4_popdef([AT_TEST])
32843284

32853285
AT_CLEANUP
3286+
3287+
3288+
## --------------- ##
3289+
## -Dcex.timeout. ##
3290+
## --------------- ##
3291+
3292+
AT_SETUP([[-Dcex.timeout]])
3293+
3294+
AT_KEYWORDS([cex])
3295+
3296+
# AT_TEST(OPTIONS)
3297+
# ----------------
3298+
m4_pushdef([AT_TEST],
3299+
[AT_DATA([[input.y]],
3300+
[[
3301+
%%
3302+
exp: %empty;
3303+
]])
3304+
AT_BISON_CHECK([[$1 input.y]], [[$2]], [[]], [m4_ifvaln([$3], [$3])])
3305+
])
3306+
3307+
# It's ok to define the timeout even if we don't run -Wcex.
3308+
AT_TEST([-Dcex.timeout=1], [0])
3309+
AT_TEST([-Dcex.timeout=1 -Wcex], [0])
3310+
AT_TEST([-Dcex.timeout=1.5 -Wcex], [0])
3311+
# No time at all. Not really wrong.
3312+
AT_TEST([-Dcex.timeout=0 -Wcex], [0])
3313+
3314+
AT_TEST([-Dcex.timeout=foo -Wcex], [1],
3315+
[[<command line>:3: error: invalid value for %define variable 'cex.timeout': 'foo']])
3316+
AT_TEST([-Dcex.timeout=-1.5 -Wcex], [1],
3317+
[[<command line>:3: error: invalid value for %define variable 'cex.timeout': '-1.5']])
3318+
3319+
m4_popdef([AT_TEST])
3320+
3321+
AT_CLEANUP

0 commit comments

Comments
 (0)