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

Re: [PATCH v2 1/2] modernize t7300

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 7, 2015, 22:43 UTC
Message-ID
<CAPig+cRqG3mG89Htmjd3a=YzMG36V3an1qUC4siJNBqHzDHQFA@mail.gmail.com>
In-Reply-To
<1449413906-23256-1-git-send-email-rouzier@gmail.com>
On Sun, Dec 6, 2015 at 9:58 AM, James <rouzier@gmail.com> wrote:
> From: James Rouzier <rouzier@gmail.com>

This would be a good place to explain how you are modernizing the test script. Right now, you're just updating to take advantage of test_path_is_foo(), but some other modernizations you could do include:

* using '>' rather than 'touch' to create empty files when the
timestamp doesn't matter (which is all cases in this script)
* (optional) replace unnecessarily complex 'mkdir -p foo' with simpler
'mkdir foo' (but leave "mkdir -p foo/bar" as is)
* drop blank lines before and after test body; for instance:
    test_expect_success 'foo' '
        blah &&
        bloo
    '
becomes:
    test_expect_success 'foo' '
        blah &&
        bloo
    '
Show 18 quoted lines
> ---
> diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
> @@ -609,32 +609,30 @@ test_expect_success 'force removal of nested git work tree' '
>  test_expect_success 'git clean -e' '
>         rm -fr repo &&
>         mkdir repo &&
> -       (
> -               cd repo &&
> -               git init &&
> -               touch known 1 2 3 &&
> -               git add known &&
> -               git clean -f -e 1 -e 2 &&
> -               test -e 1 &&
> -               test -e 2 &&
> -               ! (test -e 3) &&
> -               test -e known
> -       )
> +       cd repo &&

The previous working directory is not automatically restored at the end of the test, so this "cd" without corresponding "cd .." causes following tests to execute at the incorrect location. Unfortunately, you can't just place "cd .." at the end of a test since it will be skipped if something before the "cd .." fails. The way the existing code deals with this is by using a subshell:

    mkdir repo &&
    (
        cd repo &&
        ...
    )

The "cd repo" is inside the subshell, so it doesn't affect the parent shell, and when the subshell exits, the parent shell remains at the correct working directory (regardless of whether the test succeeded or failed). Therefore, you don't want to drop the subshell.

Show 9 quoted lines
> +       git init &&
> +       touch known 1 2 3 &&
> +       git add known &&
> +       git clean -f -e 1 -e 2 &&
> +       test_path_is_file 1 &&
> +       test_path_is_file 2 &&
> +       test_path_is_missing 3 &&
> +       test_path_is_file known
>  '
Previous: Junio C Hamano
Message 21 of 21 in “clean: new option --exclude-from”
  1. clean: new option --exclude-fromJames, Nov 26, 2015
  2. Eric SunshineNov 30, 2015
  3. Jeff KingDec 2, 2015
  4. Junio C HamanoDec 2, 2015
  5. Jeff KingDec 2, 2015
  6. Junio C HamanoDec 2, 2015
  7. Jeff KingDec 2, 2015
  8. Junio C HamanoDec 2, 2015
  9. Jeff KingDec 2, 2015
  10. Junio C HamanoDec 6, 2015
  11. Jeff KingDec 7, 2015
  12. Eric SunshineDec 1, 2015
  13. 1/2 modernize t7300James, Dec 6, 2015
  14. 2/2 clean: new option --exclude-fromJames, Dec 6, 2015
  15. Jeff KingDec 7, 2015
  16. Junio C HamanoDec 7, 2015
  17. Eric SunshineDec 7, 2015
  18. Junio C HamanoDec 7, 2015
  19. Eric SunshineDec 7, 2015
  20. Junio C HamanoDec 7, 2015
  21. Eric SunshineDec 7, 2015

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.