From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.145.9]) by sourceware.org (Postfix) with ESMTPS id 40A23389367C for ; Wed, 21 Apr 2021 21:47:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 40A23389367C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 1D45026E9C3C for ; Wed, 21 Apr 2021 16:47:44 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id ZKhElgUKWL7DmZKhElniAS; Wed, 21 Apr 2021 16:47:44 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=IHLQOIIXI+OCLggbuy3+B6g1SelFFOsnWnZ8AioEiPw=; b=lVmBB9+uT0pAf50HjTpC45cD0L vRv2jTvvPCxlpY/h2YlBYYqC3l3rzac17Dcj/3y+hZZUSqMney2pScny4ilvgtdchsMMJI2RbEYhN uoNKPuzXYIPnihwUqjkikn+gM; Received: from 71-211-182-15.hlrn.qwest.net ([71.211.182.15]:35136 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lZKhE-000R8R-C5; Wed, 21 Apr 2021 15:47:44 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Improve code coverage of Rust testing Date: Wed, 21 Apr 2021 15:47:41 -0600 Message-Id: <20210421214741.3338834-1-tom@tromey.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.182.15 X-Source-L: No X-Exim-ID: 1lZKhE-000R8R-C5 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-182-15.hlrn.qwest.net (localhost.localdomain) [71.211.182.15]:35136 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3029.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Apr 2021 21:47:48 -0000 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-21 Tom Tromey * rust-parse.c (rust_parser::parse_sizeof): Remove KW_MUT code. (struct typed_val_int) : Now ULONGEST. (rust_parser::parse_array_type): Remove negative check. (rust_lex_int_test): Change 'value' to ULONGEST. gdb/testsuite/ChangeLog 2021-04-21 Tom Tromey * 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 | 7 +++++++ gdb/rust-parse.c | 11 +++-------- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.rust/expr.exp | 2 ++ gdb/testsuite/gdb.rust/modules.exp | 4 ++++ gdb/testsuite/gdb.rust/simple.exp | 19 +++++++++++++++++++ 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index bb31782811c..2f2afcf7e9f 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -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 (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); diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp index d81b6fcbf57..603e5388c3f 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -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 diff --git a/gdb/testsuite/gdb.rust/modules.exp b/gdb/testsuite/gdb.rust/modules.exp index 6659f426a3c..4c9f4549cb7 100644 --- a/gdb/testsuite/gdb.rust/modules.exp +++ b/gdb/testsuite/gdb.rust/modules.exp @@ -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' expected" diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 0be0e94ac4c..1588e155165 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -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)" \ -- 2.26.2