Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/indent tests/indent: demonstrate the poor hand...



details:   https://anonhg.NetBSD.org/src/rev/a10e20dd3d66
branches:  trunk
changeset: 361531:a10e20dd3d66
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 13 11:07:48 2022 +0000

description:
tests/indent: demonstrate the poor handling of compound literals

diffstat:

 tests/usr.bin/indent/lsym_lbrace.c             |   4 +-
 tests/usr.bin/indent/lsym_lparen_or_lbracket.c |   4 +-
 tests/usr.bin/indent/t_errors.sh               |  50 +++++++++++++++++++++++++-
 3 files changed, 54 insertions(+), 4 deletions(-)

diffs (103 lines):

diff -r c51deff1ab66 -r a10e20dd3d66 tests/usr.bin/indent/lsym_lbrace.c
--- a/tests/usr.bin/indent/lsym_lbrace.c        Sun Feb 13 00:39:45 2022 +0000
+++ b/tests/usr.bin/indent/lsym_lbrace.c        Sun Feb 13 11:07:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lbrace.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
+/* $NetBSD: lsym_lbrace.c,v 1.3 2022/02/13 11:07:48 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -9,7 +9,7 @@
  *
  * In a function body, '{' starts a block.
  *
- * In an expression, '(type){' starts a compound expression that is typically
+ * In an expression, '(type){' starts a compound literal that is typically
  * used in an assignment to a struct or array.
  *
  * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init.
diff -r c51deff1ab66 -r a10e20dd3d66 tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sun Feb 13 00:39:45 2022 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sun Feb 13 11:07:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.2 2022/02/13 11:07:48 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -26,3 +26,5 @@
 #indent end
 
 #indent run-equals-input
+
+/* See t_errors.sh, test case 'compound_literal'. */
diff -r c51deff1ab66 -r a10e20dd3d66 tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh  Sun Feb 13 00:39:45 2022 +0000
+++ b/tests/usr.bin/indent/t_errors.sh  Sun Feb 13 11:07:48 2022 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.22 2021/11/25 21:48:23 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.23 2022/02/13 11:07:48 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -495,6 +495,53 @@
 }
 
 
+atf_test_case 'compound_literal'
+compound_literal_body()
+{
+       # Test handling of compound literals (C99 6.5.2.5), as well as casts.
+
+       cat <<EOF > code.c
+void
+function(void)
+{
+       origin =
+       ((int)
+       ((-1)*
+       (struct point){0,0}
+       )
+       );
+}
+EOF
+
+       sed '/^#/d' <<EOF > expected.out
+void
+function(void)
+{
+       origin =
+                   ((int)
+                    ((-1) *
+                     (struct point){
+# FIXME: the '{' is part of the expression, not a separate block.
+               0, 0
+# FIXME: the '}' is part of the expression, not a separate block.
+       }
+# FIXME: the ')' must be aligned with the corresponding '('.
+       )
+                   );
+}
+EOF
+       sed '/^#/d' <<EOF > expected.err
+# FIXME: The parentheses _are_ balanced, the '}' does not end the block.
+error: code.c:9: Unbalanced parentheses
+warning: code.c:10: Extra ')'
+# FIXME: There is no line 12 in the input file.
+warning: code.c:12: Extra ')'
+EOF
+
+       atf_check -s 'exit:1' -o 'file:expected.out' -e 'file:expected.err' \
+           "$indent" -nfc1 -ci12 code.c -st
+}
+
 atf_init_test_cases()
 {
        atf_add_test_case 'option_unknown'
@@ -532,4 +579,5 @@
        atf_add_test_case 'unbalanced_parentheses_3'
        atf_add_test_case 'search_stmt_comment_segv'
        atf_add_test_case 'search_stmt_fits_in_one_line'
+       atf_add_test_case 'compound_literal'
 }



Home | Main Index | Thread Index | Old Index