From 2d08b5ee8ac3b243825239caf08c898d88f0c79e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 7 Mar 2018 18:13:26 +0100 Subject: [PATCH] [math] Add tests for runtime errors And fix "isinfinite" - it's called "isinf". --- src/builtin_math.cpp | 2 +- tests/math.err | 4 ++++ tests/math.in | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index 483527ae8..062a6fa9d 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -150,7 +150,7 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_ // TODO: Really, this should be done in tinyexpr // (e.g. infinite is the result of "x / 0"), // but that's much more work. - if (std::isinfinite(v)) { + if (std::isinf(v)) { streams.err.append_format(L"%ls: Error: Result is infinite\n", cmd); streams.err.append_format(L"'%ls'\n", expression.c_str()); retval = STATUS_CMD_ERROR; diff --git a/tests/math.err b/tests/math.err index b1af734ae..c9ee082f8 100644 --- a/tests/math.err +++ b/tests/math.err @@ -24,3 +24,7 @@ math: Error: Too many arguments ^ math: Expected at least 1 args, got only 0 math: Expected at least 1 args, got only 0 +math: Error: Result is too large +'2^650' +math: Error: Result is infinite +'1 / 0' diff --git a/tests/math.in b/tests/math.in index dbc2abc3f..d8e1b3164 100644 --- a/tests/math.in +++ b/tests/math.in @@ -31,3 +31,5 @@ not math 'sin()' not math '2 + 2 4' not math not math -s 12 +not math 2^650 +not math 1 / 0