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

Re: [PATCH v2 1/2] t1300: extract and use test_cmp_config()

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 30, 2018, 04:05 UTC
Message-ID
<CAPig+cSTvewR51Vj-4MKGJKVzqFMhf4nz5yy_PdFP+EF6qMKrA@mail.gmail.com>
In-Reply-To
<20180929153005.10599-2-pclouds@gmail.com>
On Sat, Sep 29, 2018 at 11:30 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 11 quoted lines
> In many config-related tests it's common to check if a config variable
> has expected value and we want to print the differences when the test
> fails. Doing it the normal way is three lines of shell code. Let's add
> a function do to all this (and a little more).
> [...]
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -747,6 +747,30 @@ test_cmp() {
> +# similar to test_cmp but $2 is a config key instead of actual value
> +# it can also accept -C to read from a different repo, e.g.
Minor: maybe say that "-C <dir>" changes to <dir> for the git-config invocation.
Show 5 quoted lines
> +#     test_cmp_config -C xyz foo core.bar
> +#
> +# is sort of equivalent of
> +#
> +#     test "foo" = "$(git -C xyz core.bar)"
Should be: $(git -C xyz config core.bar)
> +test_cmp_config() {
> +       if [ "$1" = "-C" ]
> +       then
Style:
    if test "$1" = "-C"
    then
        ...
Show 7 quoted lines
> +               shift &&
> +               GD="-C $1" &&
> +               shift
> +       else
> +               GD=
> +       fi &&
> +       echo "$1" >expected &&

If $1 starts with a hyphen, 'echo' might try interpreting it as an option. Use printf instead:

    printf "%s\n" "$1" &&
> +       shift &&
> +       git $GD config "$@" >actual &&
> +       test_cmp expected actual

Please choose names other than "actual" and "expected" since those are likely to clobber files of the same name which the test has set up itself. (Or, at the very least, document that this function clobbers those files -- but using better filenames is preferable.)

> +}
Previous: Nguyễn Thái Ngọc DuyNext: SZEDER Gábor
Message 18 of 34 in “worktree: add per-worktree config files”
  1. worktree: add per-worktree config filesNguyễn Thái Ngọc Duy, Sep 23, 2018
  2. Eric SunshineSep 23, 2018
  3. Taylor BlauSep 24, 2018
  4. Duy NguyenSep 25, 2018
  5. Duy NguyenSep 29, 2018
  6. Junio C HamanoSep 25, 2018
  7. Duy NguyenSep 26, 2018
  8. Junio C HamanoSep 26, 2018
  9. Wherefor worktrees?Marc Branchaud, Sep 27, 2018
  10. Duy NguyenSep 27, 2018
  11. Ævar Arnfjörð BjarmasonSep 26, 2018
  12. Duy NguyenSep 27, 2018
  13. Ævar Arnfjörð BjarmasonSep 27, 2018
  14. Duy NguyenSep 27, 2018
  15. Duy NguyenSep 29, 2018
  16. 0/2 Per-worktree config filesNguyễn Thái Ngọc Duy, Sep 29, 2018
  17. 1/2 t1300: extract and use test_cmp_config()Nguyễn Thái Ngọc Duy, Sep 29, 2018
  18. Eric SunshineSep 30, 2018
  19. SZEDER GáborSep 30, 2018
  20. 2/2 worktree: add per-worktree config filesNguyễn Thái Ngọc Duy, Sep 29, 2018
  21. Eric SunshineSep 30, 2018
  22. Duy NguyenSep 30, 2018
  23. Eric SunshineSep 30, 2018
  24. Duy NguyenSep 30, 2018
  25. 0/2 Per-worktree config filesNguyễn Thái Ngọc Duy, Oct 2, 2018
  26. 1/2 t1300: extract and use test_cmp_config()Nguyễn Thái Ngọc Duy, Oct 2, 2018
  27. Eric SunshineOct 3, 2018
  28. 2/2 worktree: add per-worktree config filesNguyễn Thái Ngọc Duy, Oct 2, 2018
  29. 0/2 Per-worktree config filesNguyễn Thái Ngọc Duy, Oct 21, 2018
  30. 1/2 t1300: extract and use test_cmp_config()Nguyễn Thái Ngọc Duy, Oct 21, 2018
  31. 2/2 worktree: add per-worktree config filesNguyễn Thái Ngọc Duy, Oct 21, 2018
  32. Junio C HamanoOct 22, 2018
  33. Duy NguyenOct 22, 2018
  34. Junio C HamanoOct 25, 2018

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.