git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/7] t: fix unused files, part 1
@ 2023-03-12 20:15 Andrei Rybak
  2023-03-12 20:15 ` [PATCH v1 1/7] t1005: assert output of ls-files Andrei Rybak
                   ` (17 more replies)
  0 siblings, 18 replies; 33+ messages in thread
From: Andrei Rybak @ 2023-03-12 20:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason,
	Michael J Gruber, Jeff King, Patrick Steinhardt,
	Michael Haggerty

I've noticed that several tests in t9001-send-email.sh don't use the files
created from redirecting output of git commands.  So I wrote a crude script to
find similar issues in other tests:

    from sys import argv
    from sys import exit
    import re
    
    script = argv[1]
    
    filename_pattern = re.compile('([-a-z_A-Z]+|&1)')
    git_with_output_pattern = re.compile('git [^&"]*[ 2][>](?!/)')
    
    while True:
        res = git_with_output_pattern.search(script)
        if res is None:
            break
        filename_index = res.span()[1]
        res = filename_pattern.search(script[filename_index:])
        filename = res.group()
    
        script = script[filename_index + len(filename):]
    
        if filename == '&1':
            continue
    
        read_index = script.find(filename)
        if read_index < 0:
            print("File '" + filename + "' is unused")
            print("Script: ")
            print(script)
            exit(1)
        script = script[read_index + len(filename):]

It doesn't check the tests very throughly and has a lot of false-positives, but
this is enough for now.  I invoke it from test_expect_success() like so:

---- 8< ----
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 999d46fafe..ac2614009d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -836,6 +836,14 @@ test_expect_success () {
 		if test_run_ "$2"
 		then
 			test_ok_ "$1"
+			if ! echo "$1" | grep -q -E '(setup|preparation)'
+			then
+				if ! python3 "$TEST_DIRECTORY/../check_unused_files.py" "$2"
+				then
+					BUG "check_unused_files.py found an unused file in test '$1'"
+					return 1
+				fi
+			fi
 		else
 			test_failure_ "$@"
 		fi
---- >8 ----

Here are the fixes for the issues I've found so far -- I've gone through t0???
and t1???.

Andrei Rybak (7):
  t1005: assert output of ls-files
  t1006: assert error output of cat-file
  t1010: assert empty output of mktree
  t1302: don't create unused file
  t1400: assert output of update-ref
  t1404: don't create unused file
  t1507: assert output of rev-parse

 t/t1005-read-tree-reset.sh    | 15 ++++++++++-----
 t/t1006-cat-file.sh           |  3 ++-
 t/t1010-mktree.sh             |  6 ++++--
 t/t1302-repo-version.sh       |  2 +-
 t/t1400-update-ref.sh         |  3 +++
 t/t1404-update-ref-errors.sh  |  1 -
 t/t1507-rev-parse-upstream.sh |  6 ++++--
 7 files changed, 24 insertions(+), 12 deletions(-)

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2023-03-28 17:38 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-12 20:15 [PATCH v1 0/7] t: fix unused files, part 1 Andrei Rybak
2023-03-12 20:15 ` [PATCH v1 1/7] t1005: assert output of ls-files Andrei Rybak
2023-03-14  8:51   ` Michael J Gruber
2023-03-18 15:17     ` Andrei Rybak
2023-03-12 20:15 ` [PATCH v1 1/1] t1507: assert output of rev-parse Andrei Rybak
2023-03-12 20:24   ` Andrei Rybak
2023-03-12 20:15 ` [PATCH v1 2/7] t1006: assert error output of cat-file Andrei Rybak
2023-03-12 20:15 ` [PATCH v1 3/7] t1010: assert empty output of mktree Andrei Rybak
2023-03-13 21:38   ` Junio C Hamano
2023-03-12 20:15 ` [PATCH v1 4/7] t1302: don't create unused file Andrei Rybak
2023-03-12 20:15 ` [PATCH v1 5/7] t1400: assert output of update-ref Andrei Rybak
2023-03-12 20:15 ` [PATCH v1 6/7] t1404: don't create unused file Andrei Rybak
2023-03-13 21:56   ` Junio C Hamano
2023-03-12 20:15 ` [PATCH v1 7/7] t1507: assert output of rev-parse Andrei Rybak
2023-03-13 22:41 ` [PATCH v1 0/7] t: fix unused files, part 1 Junio C Hamano
2023-03-14 20:43   ` Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 " Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 1/7] t1005: assert output of ls-files Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 2/7] t1006: assert error output of cat-file Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 3/7] t1010: don't create unused files Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 4/7] t1302: don't create unused file Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 5/7] t1400: assert output of update-ref Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 6/7] t1404: don't create unused file Andrei Rybak
2023-03-18 15:46 ` [PATCH v2 7/7] t1507: assert output of rev-parse Andrei Rybak
2023-03-24 20:54 ` [PATCH v3 0/7] t: fix unused files, part 1 Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 1/7] t1005: assert output of ls-files Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 2/7] t1006: assert error output of cat-file Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 3/7] t1010: don't create unused files Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 4/7] t1302: don't create unused file Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 5/7] t1400: assert output of update-ref Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 6/7] t1404: don't create unused file Andrei Rybak
2023-03-24 20:54   ` [PATCH v3 7/7] t1507: assert output of rev-parse Andrei Rybak
2023-03-28 17:37   ` [PATCH v3 0/7] t: fix unused files, part 1 Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).