git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1 1/7] t1005: assert output of ls-files

From
Michael J Gruber <git@grubix.eu>
Date
Mar 14, 2023, 08:51 UTC
Message-ID
<167878391659.3913.5697119728018854973.git@grubix.eu>
In-Reply-To
<20230312201520.370234-2-rybak.a.v@gmail.com>
Andrei Rybak venit, vidit, dixit 2023-03-12 21:15:13:
Show 70 quoted lines
> Test 'reset should work' in t1005-read-tree-reset.sh compares two files
> "expect" and "actual" to assert the expected output of "git ls-files".
> Several other tests in the same file also create files "expect" and
> "actual", but don't use them in assertions.
> 
> Assert output of "git ls-files" in t1005-read-tree-reset.sh to improve
> test coverage.
> 
> Signed-off-by: Andrei Rybak <rybak.a.v@gmail.com>
> ---
>  t/t1005-read-tree-reset.sh | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/t/t1005-read-tree-reset.sh b/t/t1005-read-tree-reset.sh
> index 12e30d77d0..26be4a2b5a 100755
> --- a/t/t1005-read-tree-reset.sh
> +++ b/t/t1005-read-tree-reset.sh
> @@ -41,7 +41,8 @@ test_expect_success 'reset should remove remnants from a failed merge' '
>         git ls-files -s &&
>         read_tree_u_must_succeed --reset -u HEAD &&
>         git ls-files -s >actual &&
> -       ! test -f old
> +       ! test -f old &&
> +       test_cmp expect actual
>  '
>  
>  test_expect_success 'two-way reset should remove remnants too' '
> @@ -56,7 +57,8 @@ test_expect_success 'two-way reset should remove remnants too' '
>         git ls-files -s &&
>         read_tree_u_must_succeed --reset -u HEAD HEAD &&
>         git ls-files -s >actual &&
> -       ! test -f old
> +       ! test -f old &&
> +       test_cmp expect actual
>  '
>  
>  test_expect_success 'Porcelain reset should remove remnants too' '
> @@ -71,7 +73,8 @@ test_expect_success 'Porcelain reset should remove remnants too' '
>         git ls-files -s &&
>         git reset --hard &&
>         git ls-files -s >actual &&
> -       ! test -f old
> +       ! test -f old &&
> +       test_cmp expect actual
>  '
>  
>  test_expect_success 'Porcelain checkout -f should remove remnants too' '
> @@ -86,7 +89,8 @@ test_expect_success 'Porcelain checkout -f should remove remnants too' '
>         git ls-files -s &&
>         git checkout -f &&
>         git ls-files -s >actual &&
> -       ! test -f old
> +       ! test -f old &&
> +       test_cmp expect actual
>  '
>  
>  test_expect_success 'Porcelain checkout -f HEAD should remove remnants too' '
> @@ -101,7 +105,8 @@ test_expect_success 'Porcelain checkout -f HEAD should remove remnants too' '
>         git ls-files -s &&
>         git checkout -f HEAD &&
>         git ls-files -s >actual &&
> -       ! test -f old
> +       ! test -f old &&
> +       test_cmp expect actual
>  '
>  
>  test_done
> -- 
> 2.39.2
> 
Just in case someone else was wondering, too:

All these subtests write to `expect` just before the provided context lines, so there indeed is something to compare to, and it is the output of `git ls-files -s` before any changes and resets. As a consequence, these subtests checked only removal of remnants in the woring tree before the patch, and they check removal of index bits after the patch (additionally).

Looks fine to me - though one could probably use `git ls-files -s -o` or such instead, the suggested version is more "explicit".

Michael
Previous: Andrei RybakNext: Andrei Rybak
Message 3 of 33 in “t: fix unused files, part 1”
  1. 0/7 t: fix unused files, part 1Andrei Rybak, Mar 12, 2023
  2. 1/7 t1005: assert output of ls-filesAndrei Rybak, Mar 12, 2023
  3. Michael J GruberMar 14, 2023
  4. Andrei RybakMar 18, 2023
  5. 1/1 t1507: assert output of rev-parseAndrei Rybak, Mar 12, 2023
  6. Andrei RybakMar 12, 2023
  7. 2/7 t1006: assert error output of cat-fileAndrei Rybak, Mar 12, 2023
  8. 3/7 t1010: assert empty output of mktreeAndrei Rybak, Mar 12, 2023
  9. Junio C HamanoMar 13, 2023
  10. 4/7 t1302: don't create unused fileAndrei Rybak, Mar 12, 2023
  11. 5/7 t1400: assert output of update-refAndrei Rybak, Mar 12, 2023
  12. 6/7 t1404: don't create unused fileAndrei Rybak, Mar 12, 2023
  13. Junio C HamanoMar 13, 2023
  14. 7/7 t1507: assert output of rev-parseAndrei Rybak, Mar 12, 2023
  15. Junio C HamanoMar 13, 2023
  16. Andrei RybakMar 14, 2023
  17. 0/7 t: fix unused files, part 1Andrei Rybak, Mar 18, 2023
  18. 1/7 t1005: assert output of ls-filesAndrei Rybak, Mar 18, 2023
  19. 2/7 t1006: assert error output of cat-fileAndrei Rybak, Mar 18, 2023
  20. 3/7 t1010: don't create unused filesAndrei Rybak, Mar 18, 2023
  21. 4/7 t1302: don't create unused fileAndrei Rybak, Mar 18, 2023
  22. 5/7 t1400: assert output of update-refAndrei Rybak, Mar 18, 2023
  23. 7/7 t1507: assert output of rev-parseAndrei Rybak, Mar 18, 2023
  24. 6/7 t1404: don't create unused fileAndrei Rybak, Mar 18, 2023
  25. 0/7 t: fix unused files, part 1Andrei Rybak, Mar 24, 2023
  26. 1/7 t1005: assert output of ls-filesAndrei Rybak, Mar 24, 2023
  27. 2/7 t1006: assert error output of cat-fileAndrei Rybak, Mar 24, 2023
  28. 3/7 t1010: don't create unused filesAndrei Rybak, Mar 24, 2023
  29. 5/7 t1400: assert output of update-refAndrei Rybak, Mar 24, 2023
  30. 4/7 t1302: don't create unused fileAndrei Rybak, Mar 24, 2023
  31. 6/7 t1404: don't create unused fileAndrei Rybak, Mar 24, 2023
  32. 7/7 t1507: assert output of rev-parseAndrei Rybak, Mar 24, 2023
  33. Junio C HamanoMar 28, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.