]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Improve code coverage of Rust testing
authorTom Tromey <tom@tromey.com>
Thu, 22 Apr 2021 13:16:36 +0000 (07:16 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 22 Apr 2021 13:16:36 +0000 (07:16 -0600)
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.

gdb/ChangeLog
gdb/rust-parse.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/expr.exp
gdb/testsuite/gdb.rust/modules.exp
gdb/testsuite/gdb.rust/simple.exp

index 6187229a37d3ad64e1392ce5dd5170afad7893b8..09928110954a1095bb174784a66736cb69a52260 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2021-04-22  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * arch-utils.c (default_addressable_memory_unit_size): Return a
index bb31782811cf11ee679a334dc001ae20a71b229b..2f2afcf7e9fed5acba745ddf51002bd8dc4846a6 100644 (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);
index 5049974bf3502c36a1f3ae3a8b9d1211724524c2..3099cbacac33b2053307b64669f03a519053d1f4 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2021-04-21  Carl Love  <cel@us.ibm.com>
 
        * gdb.base/valgrind-bt.exp: Add gdb_test "break main".
index d81b6fcbf57b022669cc83abb2cceb816c992b4a..603e5388c3f797ed105028af27cfa554c308a5a4 100644 (file)
@@ -111,6 +111,8 @@ gdb_test "print ()" " = \\(\\)"
 gdb_test "print \[1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
 gdb_test "ptype \[1,2,3,4\]" "type = \\\[i32; 4\\\]"
 gdb_test "print \[mut 1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
+gdb_test "print \[1,2 3" "',' or ']' expected"
+gdb_test "print \[1 2" "',', ';', or ']' expected"
 
 gdb_test "print b\"hi rust\"" " = b\"hi rust\""
 # This isn't rusty syntax yet, but that's another bug -- this is just
index 6659f426a3c1eacb6dad7802e91f37e4c2d1bec7..4c9f4549cb7ef4db457df985b0c712c9b605f210 100644 (file)
@@ -91,3 +91,7 @@ foreach mod {mod1::inner::innest mod1::inner mod1 {}} {
 }
 
 gdb_test "print ::TWENTY_THREE" " = 23"
+
+gdb_test "print super TWENTY_THREE" "'::' expected"
+gdb_test "print super::23" "identifier expected"
+gdb_test "ptype ::Generic::<::Generic<self::Type" "'>' expected"
index 0be0e94ac4c71c1c6f9f0a5dd7893f092c314d27..1588e1551658794f36b75750e361715b08b45c75 100644 (file)
@@ -64,6 +64,7 @@ gdb_test "print j2" " = simple::Unit"
 gdb_test "ptype j2" " = struct simple::Unit"
 gdb_test "print simple::Unit" " = simple::Unit"
 gdb_test "print simple::Unit{}" " = simple::Unit"
+gdb_test "print simple::Unit{23}" "'}', '\.\.', or identifier expected"
 
 gdb_test "print f" " = \"hi bob\""
 gdb_test "print fslice" " = \"bob\""
@@ -90,6 +91,8 @@ gdb_test "print fromslice" " = 3"
 gdb_test "print slice\[0\]" " = 3"
 gdb_test "print (slice as &\[i32\])\[0\]" " = 3"
 
+gdb_test "print slice as \[i32; 73.9\]" "integer expected"
+
 gdb_test_sequence "ptype slice" "" {
     " = struct &\\\[i32\\\] \\{"
     "  data_ptr: \\*mut i32,"
@@ -131,6 +134,11 @@ gdb_test_sequence "ptype z" "" {
 }
 gdb_test "print z.1" " = 8"
 
+# Some error checks.
+gdb_test "print z.1_0" \
+    "'_' not allowed in integers in anonymous field references"
+gdb_test "print z.mut" "field name expected"
+
 gdb_test "print univariant" " = simple::Univariant::Foo{a: 1}"
 gdb_test "print univariant.a" " = 1"
 gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)"
@@ -188,6 +196,9 @@ gdb_test_sequence "ptype e" "" {
     "\\}"
 }
 
+# Test a parser error.
+gdb_test "print sizeof e" "'\\(' expected"
+
 gdb_test "print e.0" " = 73"
 gdb_test "print e.1" \
     "Cannot access field 1 of variant simple::MoreComplicated::Two, there are only 1 fields"
@@ -222,6 +233,10 @@ gdb_test "ptype empty" "fn \\(\\)"
 
 gdb_test "print (diff2 as fn(i32, i32) -> i32)(19, -2)" " = 21"
 
+gdb_test "print diff2(73, 74 75" "',' or '\\\)' expected"
+gdb_test "print (diff2 as fn i32, i32) -> i32)(19, -2)" "'\\\(' expected"
+gdb_test "print (diff2 as fn (i32, i32) i32)(19, -2)" "'->' expected"
+
 gdb_test "print \"hello rust\"" " = \"hello rust.*\""
 gdb_test "print \"hello" "Unexpected EOF in string"
 gdb_test "print r##\"hello \" rust\"##" " = \"hello \\\\\" rust.*\""
@@ -335,6 +350,10 @@ gdb_test "print (1,2,3)" "Tuple expressions not supported yet"
 gdb_test "print (1,)" "Tuple expressions not supported yet"
 gdb_test "print (1)" " = 1"
 
+# Test a syntax error in tuple expressions.
+gdb_test "print (1,2,," "unexpected token"
+gdb_test "print (1,2 8" "',' or '\\\)' expected"
+
 gdb_test "print 23..97.0" "Range expression with different types"
 
 gdb_test "print (*parametrized.next.val)" \