diff --git a/tests/copyright_gate_test.sh b/tests/copyright_gate_test.sh index f73a8d4a2..09d4e6423 100755 --- a/tests/copyright_gate_test.sh +++ b/tests/copyright_gate_test.sh @@ -161,6 +161,17 @@ check "...and exactly one SPDX line is left in the window" \ # left the copy in place, so the file it had just written still failed the very check that sent it there. printf '%s%s\nx = 1\n' "$NOTICE_BLOCK" "$NOTICE_BLOCK" > "$tmp/doubled.py" git -C "$tmp" add doubled.py +# (checked with `case`, not `python --check | grep -q`: this file runs under `set -o pipefail` and `--check` exits 1 BY DESIGN +# for the duplicate it just reported, so the pipeline would return 1 even when grep matched -- the same `cmd | grep` trap that +# makes `$?` the pipeline's rather than the command's.) +# the report must name the command that repairs it: the old text said "delete the second copy", i.e. hand-edit a file that +# `--fix` had been failing on and now repairs (engine#2192), so a reader was told to do by hand what the tool does. +# assigned first, not nested: `\"` inside `$( )` inside a double-quoted argument is NOT unescaped by bash, so a nested form +# comparing the captured output passes the quote characters into the path (`cd: "/tmp/..."`). +dup_report=$( cd "$tmp" && python3 copyright.py --check 2>&1 ) +check "the duplicate report names --fix rather than telling the reader to edit by hand" \ + "case \"\$dup_report\" in *'keeps the first copy'*) true ;; *) false ;; esac" \ + "$( cd "$tmp" && python3 copyright.py --check 2>&1 | grep duplicated )" ( cd "$tmp" && python3 copyright.py --fix >/dev/null 2>&1 ) check "--fix on a doubled block leaves a file that its own --check accepts" \ "! ( cd \"$tmp\" && python3 copyright.py --check 2>&1 | grep -q duplicated )" \ diff --git a/tools/copyright.py b/tools/copyright.py index f705f0b89..65e993989 100755 --- a/tools/copyright.py +++ b/tools/copyright.py @@ -278,7 +278,7 @@ def repair_notice(text, block): # A SECOND canonical notice is the same defect as a near-miss beside the first: the block pasted twice. `--check` # has always reported it (`duplicated_notice`); `--fix` used to print "repaired" and leave the copy in place, so the # file it had just written still failed the very check that sent it there. The first occurrence is kept and later - # ones dropped, which is what "delete the second copy" means. + # ones dropped, which is what the report line now tells the reader --fix will do. if canonical_notice_line(line): key = re.sub(r"^\W+", "", line).strip() if key in seen_canonical: @@ -363,7 +363,7 @@ def listing(*args): missing.append(path) for path in duplicated: - print("copyright notice duplicated inside the header window (delete the second copy):", path) + print("copyright notice duplicated inside the header window (--fix keeps the first copy and drops the rest):", path) for path in unknown: print("no comment style known (add one to LINE_STYLES/BLOCK_STYLES or EXEMPT):", path) for path in missing: