Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src tests/lint: test dangling else
details: https://anonhg.NetBSD.org/src/rev/4b013a72d372
branches: trunk
changeset: 984554:4b013a72d372
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jul 11 18:58:13 2021 +0000
description:
tests/lint: test dangling else
diffstat:
distrib/sets/lists/tests/mi | 4 +++-
tests/usr.bin/xlint/lint1/Makefile | 4 +++-
tests/usr.bin/xlint/lint1/stmt_if.c | 28 ++++++++++++++++++++++++++++
tests/usr.bin/xlint/lint1/stmt_if.exp | 1 +
4 files changed, 35 insertions(+), 2 deletions(-)
diffs (73 lines):
diff -r 94262ac1f22e -r 4b013a72d372 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sun Jul 11 18:22:02 2021 +0000
+++ b/distrib/sets/lists/tests/mi Sun Jul 11 18:58:13 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1083 2021/07/10 18:25:57 rillig Exp $
+# $NetBSD: mi,v 1.1084 2021/07/11 18:58:13 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6976,6 +6976,8 @@
./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/stmt_for.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/stmt_for.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/stmt_if.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/stmt_if.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/t_integration tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/ztest tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/ztest/Atffile tests-usr.bin-tests compattestfile,atf
diff -r 94262ac1f22e -r 4b013a72d372 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile Sun Jul 11 18:22:02 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile Sun Jul 11 18:58:13 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.84 2021/07/10 18:25:57 rillig Exp $
+# $NetBSD: Makefile,v 1.85 2021/07/11 18:58:13 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 345 # see lint1/err.c
@@ -181,6 +181,8 @@
FILES+= op_shl_lp64.exp
FILES+= stmt_for.c
FILES+= stmt_for.exp
+FILES+= stmt_if.c
+FILES+= stmt_if.exp
# Note: only works for adding tests.
# To remove a test, the $$mi file must be edited manually.
diff -r 94262ac1f22e -r 4b013a72d372 tests/usr.bin/xlint/lint1/stmt_if.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/stmt_if.c Sun Jul 11 18:58:13 2021 +0000
@@ -0,0 +1,28 @@
+/* $NetBSD: stmt_if.c,v 1.1 2021/07/11 18:58:13 rillig Exp $ */
+# 3 "stmt_if.c"
+
+/*
+ * Test parsing of 'if' statements.
+ */
+
+void println(const char *);
+
+void
+dangling_else(int x)
+{
+ if (x > 0)
+ if (x > 10)
+ println("> 10");
+ /* This 'else' is bound to the closest unfinished 'if'. */
+ else
+ println("> 0");
+ /*
+ * If the above 'else' were bound to the other 'if', the next 'else'
+ * would have no corresponding 'if', resulting in a syntax error.
+ */
+ else
+ println("not positive");
+ /* expect+1: syntax error 'else' [249] */
+ else
+ println("syntax error");
+}
diff -r 94262ac1f22e -r 4b013a72d372 tests/usr.bin/xlint/lint1/stmt_if.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/stmt_if.exp Sun Jul 11 18:58:13 2021 +0000
@@ -0,0 +1,1 @@
+stmt_if.c(26): error: syntax error 'else' [249]
Home |
Main Index |
Thread Index |
Old Index