Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: do not overwrite expec...



details:   https://anonhg.NetBSD.org/src/rev/dd9655109aa0
branches:  trunk
changeset: 376686:dd9655109aa0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jun 28 20:51:31 2023 +0000

description:
tests/lint: do not overwrite expected files that only differ in spaces

diffstat:

 tests/usr.bin/xlint/lint1/accept.sh |  21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diffs (50 lines):

diff -r e82fe7f74c18 -r dd9655109aa0 tests/usr.bin/xlint/lint1/accept.sh
--- a/tests/usr.bin/xlint/lint1/accept.sh       Wed Jun 28 17:53:21 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/accept.sh       Wed Jun 28 20:51:31 2023 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: accept.sh,v 1.11 2022/06/19 11:50:42 rillig Exp $
+# $NetBSD: accept.sh,v 1.12 2023/06/28 20:51:31 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -43,6 +43,7 @@ for pattern in "$@"; do
        for cfile in *$pattern*.c; do
                base=${cfile%.*}
                expfile="$base.exp"
+               ln_tmp_file="$base.exp-ln.tmp"
                ln_file="$base.exp-ln"
 
                configure_test_case "$cfile"
@@ -57,7 +58,7 @@ for pattern in "$@"; do
 
                # shellcheck disable=SC2154
                # shellcheck disable=SC2086
-               if "$lint1" $flags "$base.c" "$ln_file" > "$expfile"; then
+               if "$lint1" $flags "$base.c" "$ln_tmp_file" > "$expfile"; then
                        if [ -s "$expfile" ]; then
                                echo "$base produces output but exits successfully"
                                sed 's,^,| ,' "$expfile"
@@ -67,6 +68,22 @@ for pattern in "$@"; do
                        continue
                fi
 
+               if [ ! -f "$ln_tmp_file" ]; then
+                       : 'No cleanup necessary.'
+               elif [ "$ln_file" = '/dev/null' ]; then
+                       rm "$ln_tmp_file"
+               else
+                       if tr -d ' \t' < "$ln_file" > "$ln_file.trimmed.tmp" &&
+                           tr -d ' \t' < "$ln_tmp_file" > "$ln_tmp_file.trimmed.tmp" &&
+                           cmp -s "$ln_file.trimmed.tmp" "$ln_tmp_file.trimmed.tmp"; then
+                               rm "$ln_tmp_file"
+                       else
+                               echo "Replacing $ln_file"
+                               mv "$ln_tmp_file" "$ln_file"
+                       fi
+                       rm -f "$ln_file.trimmed.tmp" "$ln_tmp_file.trimmed.tmp"
+               fi
+
                case "$base" in (msg_*)
                        if grep 'This message is not used\.' "$cfile" >/dev/null; then
                                : 'Skip further checks.'



Home | Main Index | Thread Index | Old Index