Sun Feb 13 11:07:48 2022 UTC ()
tests/indent: demonstrate the poor handling of compound literals


(rillig)
diff -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lbrace.c
diff -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
diff -r1.22 -r1.23 src/tests/usr.bin/indent/t_errors.sh

cvs diff -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lbrace.c (expand / switch to unified diff)

--- src/tests/usr.bin/indent/lsym_lbrace.c 2021/11/20 16:54:17 1.2
+++ src/tests/usr.bin/indent/lsym_lbrace.c 2022/02/13 11:07:48 1.3
@@ -1,22 +1,22 @@ @@ -1,22 +1,22 @@
1/* $NetBSD: lsym_lbrace.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */ 1/* $NetBSD: lsym_lbrace.c,v 1.3 2022/02/13 11:07:48 rillig Exp $ */
2/* $FreeBSD$ */ 2/* $FreeBSD$ */
3 3
4/* 4/*
5 * Tests for the token lsym_lbrace, which represents a '{' in these contexts: 5 * Tests for the token lsym_lbrace, which represents a '{' in these contexts:
6 * 6 *
7 * In an initializer, '{' starts an inner group of initializers, usually to 7 * In an initializer, '{' starts an inner group of initializers, usually to
8 * initialize a nested struct, union or array. 8 * initialize a nested struct, union or array.
9 * 9 *
10 * In a function body, '{' starts a block. 10 * In a function body, '{' starts a block.
11 * 11 *
12 * In an expression, '(type){' starts a compound expression that is typically 12 * In an expression, '(type){' starts a compound literal that is typically
13 * used in an assignment to a struct or array. 13 * used in an assignment to a struct or array.
14 * 14 *
15 * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init. 15 * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init.
16 */ 16 */
17 17
18#indent input 18#indent input
19// TODO: add input 19// TODO: add input
20#indent end 20#indent end
21 21
22#indent run-equals-input 22#indent run-equals-input

cvs diff -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c (expand / switch to unified diff)

--- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c 2021/11/18 21:19:19 1.1
+++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c 2022/02/13 11:07:48 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */ 1/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.2 2022/02/13 11:07:48 rillig Exp $ */
2/* $FreeBSD$ */ 2/* $FreeBSD$ */
3 3
4/* 4/*
5 * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '[' 5 * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
6 * in these contexts: 6 * in these contexts:
7 * 7 *
8 * In a type name, '(' constructs a function type. 8 * In a type name, '(' constructs a function type.
9 * 9 *
10 * In an expression, '(' starts an inner expression to override the usual 10 * In an expression, '(' starts an inner expression to override the usual
11 * operator precedence. 11 * operator precedence.
12 * 12 *
13 * In an expression, an identifier followed by '(' starts a function call 13 * In an expression, an identifier followed by '(' starts a function call
14 * expression. 14 * expression.
@@ -16,13 +16,15 @@ @@ -16,13 +16,15 @@
16 * In a 'sizeof' expression, '(' is required if the argument is a type name. 16 * In a 'sizeof' expression, '(' is required if the argument is a type name.
17 * 17 *
18 * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling 18 * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling
19 * expression must be enclosed in '(' and ')'. 19 * expression must be enclosed in '(' and ')'.
20 * 20 *
21 * In an expression, '(' followed by a type name starts a cast expression. 21 * In an expression, '(' followed by a type name starts a cast expression.
22 */ 22 */
23 23
24#indent input 24#indent input
25// TODO: add input 25// TODO: add input
26#indent end 26#indent end
27 27
28#indent run-equals-input 28#indent run-equals-input
 29
 30/* See t_errors.sh, test case 'compound_literal'. */

cvs diff -r1.22 -r1.23 src/tests/usr.bin/indent/t_errors.sh (expand / switch to unified diff)

--- src/tests/usr.bin/indent/t_errors.sh 2021/11/25 21:48:23 1.22
+++ src/tests/usr.bin/indent/t_errors.sh 2022/02/13 11:07:48 1.23
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: t_errors.sh,v 1.22 2021/11/25 21:48:23 rillig Exp $ 2# $NetBSD: t_errors.sh,v 1.23 2022/02/13 11:07:48 rillig Exp $
3# 3#
4# Copyright (c) 2021 The NetBSD Foundation, Inc. 4# Copyright (c) 2021 The NetBSD Foundation, Inc.
5# All rights reserved. 5# All rights reserved.
6# 6#
7# Redistribution and use in source and binary forms, with or without 7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions 8# modification, are permitted provided that the following conditions
9# are met: 9# are met:
10# 1. Redistributions of source code must retain the above copyright 10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer. 11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright 12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the 13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution. 14# documentation and/or other materials provided with the distribution.
15# 15#
@@ -485,26 +485,73 @@ f(void) @@ -485,26 +485,73 @@ f(void)
485{ 485{
486 if (0) 486 if (0)
487 /* 487 /*
488 * 0123456789012345678901 488 * 0123456789012345678901
489 */ ; 489 */ ;
490} 490}
491EOF 491EOF
492 492
493 atf_check -o 'file:expected.out' \ 493 atf_check -o 'file:expected.out' \
494 "$indent" -l34 code.c -st 494 "$indent" -l34 code.c -st
495} 495}
496 496
497 497
 498atf_test_case 'compound_literal'
 499compound_literal_body()
 500{
 501 # Test handling of compound literals (C99 6.5.2.5), as well as casts.
 502
 503 cat <<EOF > code.c
 504void
 505function(void)
 506{
 507 origin =
 508 ((int)
 509 ((-1)*
 510 (struct point){0,0}
 511 )
 512 );
 513}
 514EOF
 515
 516 sed '/^#/d' <<EOF > expected.out
 517void
 518function(void)
 519{
 520 origin =
 521 ((int)
 522 ((-1) *
 523 (struct point){
 524# FIXME: the '{' is part of the expression, not a separate block.
 525 0, 0
 526# FIXME: the '}' is part of the expression, not a separate block.
 527 }
 528# FIXME: the ')' must be aligned with the corresponding '('.
 529 )
 530 );
 531}
 532EOF
 533 sed '/^#/d' <<EOF > expected.err
 534# FIXME: The parentheses _are_ balanced, the '}' does not end the block.
 535error: code.c:9: Unbalanced parentheses
 536warning: code.c:10: Extra ')'
 537# FIXME: There is no line 12 in the input file.
 538warning: code.c:12: Extra ')'
 539EOF
 540
 541 atf_check -s 'exit:1' -o 'file:expected.out' -e 'file:expected.err' \
 542 "$indent" -nfc1 -ci12 code.c -st
 543}
 544
498atf_init_test_cases() 545atf_init_test_cases()
499{ 546{
500 atf_add_test_case 'option_unknown' 547 atf_add_test_case 'option_unknown'
501 atf_add_test_case 'option_bool_trailing_garbage' 548 atf_add_test_case 'option_bool_trailing_garbage'
502 atf_add_test_case 'option_int_missing_argument' 549 atf_add_test_case 'option_int_missing_argument'
503 atf_add_test_case 'option_profile_not_found' 550 atf_add_test_case 'option_profile_not_found'
504 atf_add_test_case 'option_buffer_overflow' 551 atf_add_test_case 'option_buffer_overflow'
505 atf_add_test_case 'option_typedefs_not_found' 552 atf_add_test_case 'option_typedefs_not_found'
506 atf_add_test_case 'option_special_missing_param' 553 atf_add_test_case 'option_special_missing_param'
507 atf_add_test_case 'option_tabsize_negative' 554 atf_add_test_case 'option_tabsize_negative'
508 atf_add_test_case 'option_tabsize_zero' 555 atf_add_test_case 'option_tabsize_zero'
509 atf_add_test_case 'option_tabsize_large' 556 atf_add_test_case 'option_tabsize_large'
510 atf_add_test_case 'option_tabsize_very_large' 557 atf_add_test_case 'option_tabsize_very_large'
@@ -522,14 +569,15 @@ atf_init_test_cases() @@ -522,14 +569,15 @@ atf_init_test_cases()
522 atf_add_test_case 'argument_output_equals_input_file' 569 atf_add_test_case 'argument_output_equals_input_file'
523 atf_add_test_case 'argument_output_enoent' 570 atf_add_test_case 'argument_output_enoent'
524 atf_add_test_case 'argument_too_many' 571 atf_add_test_case 'argument_too_many'
525 atf_add_test_case 'unexpected_end_of_file' 572 atf_add_test_case 'unexpected_end_of_file'
526 atf_add_test_case 'unexpected_closing_brace_top_level' 573 atf_add_test_case 'unexpected_closing_brace_top_level'
527 atf_add_test_case 'unexpected_closing_brace_decl' 574 atf_add_test_case 'unexpected_closing_brace_decl'
528 atf_add_test_case 'preprocessing_overflow' 575 atf_add_test_case 'preprocessing_overflow'
529 atf_add_test_case 'preprocessing_unrecognized' 576 atf_add_test_case 'preprocessing_unrecognized'
530 atf_add_test_case 'unbalanced_parentheses_1' 577 atf_add_test_case 'unbalanced_parentheses_1'
531 atf_add_test_case 'unbalanced_parentheses_2' 578 atf_add_test_case 'unbalanced_parentheses_2'
532 atf_add_test_case 'unbalanced_parentheses_3' 579 atf_add_test_case 'unbalanced_parentheses_3'
533 atf_add_test_case 'search_stmt_comment_segv' 580 atf_add_test_case 'search_stmt_comment_segv'
534 atf_add_test_case 'search_stmt_fits_in_one_line' 581 atf_add_test_case 'search_stmt_fits_in_one_line'
 582 atf_add_test_case 'compound_literal'
535} 583}