Module Name: src
Committed By: rillig
Date: Sun Feb 13 11:07:48 UTC 2022
Modified Files:
src/tests/usr.bin/indent: lsym_lbrace.c lsym_lparen_or_lbracket.c
t_errors.sh
Log Message:
tests/indent: demonstrate the poor handling of compound literals
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lbrace.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/indent/t_errors.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/indent/lsym_lbrace.c
diff -u src/tests/usr.bin/indent/lsym_lbrace.c:1.2 src/tests/usr.bin/indent/lsym_lbrace.c:1.3
--- src/tests/usr.bin/indent/lsym_lbrace.c:1.2 Sat Nov 20 16:54:17 2021
+++ src/tests/usr.bin/indent/lsym_lbrace.c Sun Feb 13 11:07:48 2022
@@ -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.
Index: src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.1 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.2
--- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.1 Thu Nov 18 21:19:19 2021
+++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sun Feb 13 11:07:48 2022
@@ -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'. */
Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.22 src/tests/usr.bin/indent/t_errors.sh:1.23
--- src/tests/usr.bin/indent/t_errors.sh:1.22 Thu Nov 25 21:48:23 2021
+++ src/tests/usr.bin/indent/t_errors.sh Sun Feb 13 11:07:48 2022
@@ -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 @@ EOF
}
+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_init_test_cases()
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'
}