From cd656d410bb534aa1650a598a16b1100d6ba19fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 14 Mar 2021 22:48:12 +0100 Subject: [PATCH 1/5] Add tests for forget-results command --- test/forget-results.t | 119 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 test/forget-results.t diff --git a/test/forget-results.t b/test/forget-results.t new file mode 100755 index 0000000..2f4bb35 --- /dev/null +++ b/test/forget-results.t @@ -0,0 +1,119 @@ +#! /bin/sh + +test_description="Test forgetting test results" + +. ./sharness.sh + +test_expect_success 'Set up test repository' ' + git init . && + git config user.name "Test User" && + git config user.email "user@example.com" && + for i in $(seq 0 3) + do + echo $i >number && + git add number && + git commit -m "Number $i" + done && + true +' + +test_expect_success 'Add tests' ' + git-test add true && + git-test add -t t1 true && + git-test add -t t2 true && + git-test add -t t3 true && + true +' + +test_expect_success 'Add some simulated test results' ' + git notes --ref=tests/default add -m "good" HEAD~0^{tree} && + git notes --ref=tests/default add -m "good" HEAD~1^{tree} && + git notes --ref=tests/default add -m "good" HEAD~2^{tree} && + git notes --ref=tests/default add -m "good" HEAD~3^{tree} && + true && + git notes --ref=tests/t1 add -m "good" HEAD~0^{tree} && + git notes --ref=tests/t1 add -m "good" HEAD~1^{tree} && + git notes --ref=tests/t1 add -m "good" HEAD~2^{tree} && + git notes --ref=tests/t1 add -m "bad" HEAD~3^{tree} && + true && + git notes --ref=tests/t2 add -m "good" HEAD~1^{tree} && + git notes --ref=tests/t2 add -m "bad" HEAD~2^{tree} && + true +' + +test_expect_success 'Verify number of notes' ' + echo 4 > expected && + git notes --ref=tests/default list | wc -l >actual && + test_cmp expected actual && + true && + echo 4 > expected && + git notes --ref=tests/t1 list | wc -l >actual && + test_cmp expected actual && + true && + echo 2 > expected && + git notes --ref=tests/t2 list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t3 list | wc -l >actual && + test_cmp expected actual && + true +' + +test_expect_success 'Forgetting default and not affecting other tests' ' + rm -f expected && + touch expected && + git-test forget-results >actual && + test_cmp expected actual && + echo 0 > expected && + git notes --ref=tests/default list | wc -l >actual && + test_cmp expected actual && + true && + echo 4 > expected && + git notes --ref=tests/t1 list | wc -l >actual && + test_cmp expected actual && + true && + echo 2 > expected && + git notes --ref=tests/t2 list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t3 list | wc -l >actual && + test_cmp expected actual && + true +' + + +test_expect_success 'Add default test results again' ' + git notes --ref=tests/default add -m "good" HEAD~0^{tree} && + git notes --ref=tests/default add -m "good" HEAD~1^{tree} && + git notes --ref=tests/default add -m "good" HEAD~2^{tree} && + git notes --ref=tests/default add -m "good" HEAD~3^{tree} && + true +' + + +test_expect_success 'Forgetting t1 and not affecting other tests' ' + rm -f expected && + touch expected && + git-test forget-results --test t1 >actual && + test_cmp expected actual && + echo 4 > expected && + git notes --ref=tests/default list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t1 list | wc -l >actual && + test_cmp expected actual && + true && + echo 2 > expected && + git notes --ref=tests/t2 list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t3 list | wc -l >actual && + test_cmp expected actual && + true +' + +test_done From 7dead6af4d48fb34c4568273351cbe4ba19b5c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 14 Mar 2021 20:48:43 +0100 Subject: [PATCH 2/5] Print results from forgetting all test results --- bin/git-test | 3 +++ test/forget-results.t | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/git-test b/bin/git-test index d8ddbb2..1f89ef1 100755 --- a/bin/git-test +++ b/bin/git-test @@ -838,6 +838,9 @@ def cmd_forget_results(parser, options): test.initialize_status( 'Test results reinitialized by \'git test forget-results\'' ) + sys.stdout.write(colored('All test results for test ', AnsiColor.GREEN)) + sys.stdout.write(colored(test.name, AnsiColor.CYAN)) + sys.stdout.write(colored(' were forgotten.\n', AnsiColor.GREEN)) test_re = re.compile(r'^test\.(?P.*)\.command$') diff --git a/test/forget-results.t b/test/forget-results.t index 2f4bb35..111fe7e 100755 --- a/test/forget-results.t +++ b/test/forget-results.t @@ -61,8 +61,7 @@ test_expect_success 'Verify number of notes' ' ' test_expect_success 'Forgetting default and not affecting other tests' ' - rm -f expected && - touch expected && + echo "All test results for test default were forgotten." >expected && git-test forget-results >actual && test_cmp expected actual && echo 0 > expected && @@ -94,8 +93,7 @@ test_expect_success 'Add default test results again' ' test_expect_success 'Forgetting t1 and not affecting other tests' ' - rm -f expected && - touch expected && + echo "All test results for test t1 were forgotten." >expected && git-test forget-results --test t1 >actual && test_cmp expected actual && echo 4 > expected && From 3a82167d9ec89bc7a566081a5a313b82cd4047d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 14 Mar 2021 19:29:23 +0100 Subject: [PATCH 3/5] Add --all argument to forget-results --- README.md | 2 +- bin/git-test | 14 ++++++++++++++ test/forget-results.t | 24 ++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 82e79b0..b2a6218 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ If you want to forget particular old test results without retesting, run `git te If you want to permanently forget *all* stored results for a particular test (e.g., if something in your environment has changed), run - git test forget-results [--test=] + git test forget-results --all [--test=] ### Continue on test failures diff --git a/bin/git-test b/bin/git-test index 1f89ef1..79fccdc 100755 --- a/bin/git-test +++ b/bin/git-test @@ -828,6 +828,16 @@ def cmd_results(parser, options): def cmd_forget_results(parser, options): test = Test(options.test) + NO_ARGUMENTS_WARNING = """\ +WARNING: Which test results to forget was not specified. Assuming --all for +backwards compability. This backwards compability might be removed in the +future, please update to explicit specify what should be removed. +""" + + if not options.all: + sys.stderr.write(colored(NO_ARGUMENTS_WARNING, AnsiColor.CYAN)) + options.all = True + cmd = ['git', 'config', 'test.%s.command' % (test.name,)] try: chatty_call(cmd) @@ -1061,6 +1071,10 @@ def main(args): action='store', default='default', help='name of test whose results should be forgotten (default is \'default\')', ) + subparser.add_argument( + '--all', action='store_true', + help='forget all existing test results for the current test', + ) add_verbosity_options(subparser) subparser = subparsers.add_parser( diff --git a/test/forget-results.t b/test/forget-results.t index 111fe7e..f062002 100755 --- a/test/forget-results.t +++ b/test/forget-results.t @@ -62,7 +62,8 @@ test_expect_success 'Verify number of notes' ' test_expect_success 'Forgetting default and not affecting other tests' ' echo "All test results for test default were forgotten." >expected && - git-test forget-results >actual && + git-test forget-results --all >actual && + test_must_fail grep -q WARNING actual test_cmp expected actual && echo 0 > expected && git notes --ref=tests/default list | wc -l >actual && @@ -94,7 +95,8 @@ test_expect_success 'Add default test results again' ' test_expect_success 'Forgetting t1 and not affecting other tests' ' echo "All test results for test t1 were forgotten." >expected && - git-test forget-results --test t1 >actual && + git-test forget-results --all --test t1 >actual && + test_must_fail grep -q WARNING actual test_cmp expected actual && echo 4 > expected && git notes --ref=tests/default list | wc -l >actual && @@ -114,4 +116,22 @@ test_expect_success 'Forgetting t1 and not affecting other tests' ' true ' +# sed command: On line 1 remove from the first space and the rest, and delete +# lines 2 and till the last line, e.g. only keep first word on first line. +test_expect_success 'Missing --all argument produces warning' ' + echo "WARNING:" >expected + git-test forget-results 2>actual && + sed -i "1s/ .*//; 2,\$d" actual && + test_cmp expected actual +' + + +test_expect_success 'Should not give output on non-existent test' ' + rm -f expected && + touch expected && + git-test forget-results --all -t this-test-does-not-exist >actual && + test_cmp expected actual && + true +' + test_done From dfc441d15c2ddec219430011b6d8f4647b5fc251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 14 Mar 2021 20:02:54 +0100 Subject: [PATCH 4/5] Refactor: extract forget_results_for_test --- bin/git-test | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/git-test b/bin/git-test index 79fccdc..f9c52e1 100755 --- a/bin/git-test +++ b/bin/git-test @@ -826,8 +826,6 @@ def cmd_results(parser, options): def cmd_forget_results(parser, options): - test = Test(options.test) - NO_ARGUMENTS_WARNING = """\ WARNING: Which test results to forget was not specified. Assuming --all for backwards compability. This backwards compability might be removed in the @@ -838,6 +836,12 @@ future, please update to explicit specify what should be removed. sys.stderr.write(colored(NO_ARGUMENTS_WARNING, AnsiColor.CYAN)) options.all = True + forget_results_for_test(options.test) + + +def forget_results_for_test(name): + test = Test(name) + cmd = ['git', 'config', 'test.%s.command' % (test.name,)] try: chatty_call(cmd) From 24047cc7328c73dea8e78f3a332ecbaed9671df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 14 Mar 2021 22:48:12 +0100 Subject: [PATCH 5/5] Add --all-tests option to forget-results --- README.md | 4 ++++ bin/git-test | 13 +++++++++++-- test/forget-results.t | 29 ++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2a6218..068f860 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,10 @@ If you want to permanently forget *all* stored results for a particular test (e. git test forget-results --all [--test=] +If you want to permanently forget *all* stored results for *all test*, run + + git test forget-results --all-tests + ### Continue on test failures Normally, `git test run` stops at the first broken commit that it finds. If you'd prefer for it to continue even after a failure, use the `--keep-going`/`-k` option. diff --git a/bin/git-test b/bin/git-test index f9c52e1..6490e94 100755 --- a/bin/git-test +++ b/bin/git-test @@ -832,11 +832,15 @@ backwards compability. This backwards compability might be removed in the future, please update to explicit specify what should be removed. """ - if not options.all: + if not (options.all or options.all_tests): sys.stderr.write(colored(NO_ARGUMENTS_WARNING, AnsiColor.CYAN)) options.all = True - forget_results_for_test(options.test) + if options.all_tests: + for test in iter_tests(): + forget_results_for_test(test.name) + else: + forget_results_for_test(options.test) def forget_results_for_test(name): @@ -1079,6 +1083,11 @@ def main(args): '--all', action='store_true', help='forget all existing test results for the current test', ) + subparser.add_argument( + '--all-tests', + action='store_true', + help='forget all existing test results for all tests', + ) add_verbosity_options(subparser) subparser = subparsers.add_parser( diff --git a/test/forget-results.t b/test/forget-results.t index f062002..dd7d3c0 100755 --- a/test/forget-results.t +++ b/test/forget-results.t @@ -116,9 +116,36 @@ test_expect_success 'Forgetting t1 and not affecting other tests' ' true ' +test_expect_success 'Forgetting all test results' ' + echo "All test results for test default were forgotten." >expected && + echo "All test results for test t1 were forgotten." >>expected && + echo "All test results for test t2 were forgotten." >>expected && + echo "All test results for test t3 were forgotten." >>expected && + git-test forget-results --all-tests >actual && + test_must_fail grep -q WARNING actual + test_cmp expected actual && + echo 0 > expected && + git notes --ref=tests/default list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t1 list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t2 list | wc -l >actual && + test_cmp expected actual && + true && + echo 0 > expected && + git notes --ref=tests/t3 list | wc -l >actual && + test_cmp expected actual && + true +' + + # sed command: On line 1 remove from the first space and the rest, and delete # lines 2 and till the last line, e.g. only keep first word on first line. -test_expect_success 'Missing --all argument produces warning' ' +test_expect_success 'Missing --all or --all-tests argument produces warning' ' echo "WARNING:" >expected git-test forget-results 2>actual && sed -i "1s/ .*//; 2,\$d" actual &&