Improve code coverage of Rust testing

I enabled code coverage and ran the gdb test suite, and noticed that
the new Rust parser was missing testing on a few lines that were easy
to cover.  This patch mostly adds tests for certain syntax errors; but
this process also uncovered a couple of real bugs: I must have
cut-and-pasted the 'sizeof' parsing code from some other code, because
it is checking for KW_MUT (the old bison parser did not do this), and
the array length check is actually impossible because a negative
number like '-1' is parsed as two tokens.

gdb/ChangeLog
2021-04-22  Tom Tromey  <tom@tromey.com>

	* rust-parse.c (rust_parser::parse_sizeof): Remove KW_MUT code.
	(struct typed_val_int) <val>: Now ULONGEST.
	(rust_parser::parse_array_type): Remove negative check.
	(rust_lex_int_test): Change 'value' to ULONGEST.

gdb/testsuite/ChangeLog
2021-04-22  Tom Tromey  <tom@tromey.com>

	* gdb.rust/modules.exp: Add checks for syntax errors.
	* gdb.rust/expr.exp: Add checks for syntax errors.
	* gdb.rust/simple.exp: Add checks for syntax errors.
This commit is contained in:
Tom Tromey
2021-04-22 07:16:36 -06:00
parent b11b2969a9
commit 22f80c0f77
6 changed files with 41 additions and 8 deletions

View File

@ -126,7 +126,7 @@ enum token_type : int
struct typed_val_int
{
LONGEST val;
ULONGEST val;
struct type *type;
};
@ -1447,9 +1447,6 @@ rust_parser::parse_sizeof ()
{
assume (KW_SIZEOF);
if (current_token == KW_MUT)
lex ();
require ('(');
operation_up result = make_operation<unop_sizeof_operation> (parse_expr ());
require (')');
@ -1600,9 +1597,7 @@ rust_parser::parse_array_type ()
if (current_token != INTEGER && current_token != DECIMAL_INTEGER)
error (_("integer expected"));
LONGEST val = current_int_val.val;
if (val < 0)
error (_("Negative array length"));
ULONGEST val = current_int_val.val;
lex ();
require (']');
@ -2117,7 +2112,7 @@ rust_lex_test_one (rust_parser *parser, const char *input, int expected)
static void
rust_lex_int_test (rust_parser *parser, const char *input,
LONGEST value, int kind)
ULONGEST value, int kind)
{
rust_lex_test_one (parser, input, kind);
SELF_CHECK (parser->current_int_val.val == value);