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

Re: guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Sep 7, 2010, 06:12 UTC
Message-ID
<20100907061213.GU1182@burratino>
In-Reply-To
<20100907055636.GA30357@sigill.intra.peff.net>
Jeff King wrote:
Show 18 quoted lines
> Perhaps we could refactor it into a
> set of two functions that keep state? E.g., something like:
> 
> test_start 'setup'
> cat >expect <<EOF
> ... whatever ...
> EOF
> test_end success
> 
> test_start 'description'
> git frob >actual &&
> test_cmp expect actual
> test_end success
> 
> where test_start would set up >&3 and >&4 as usual, and test_end would
> check $? and report the status. The biggest problem I see is that we
> never have the actual shell script snippet as a string, so we don't have
> a way of printing it for "-v" (or on failure). Hmm.

FWIW I don't mind this idea (to be used as an alternative to test_expect_success when quoting issues get ugly). Maybe the harness could fetch the snippet by parsing $0? (Sorry, couldn't resist. Something simpler might be possible: e.g., a special

test_expect_success 'description' - <<\test_end cat >expect <<EOF ... whatever ... EOF test_end

syntax.)
Show 11 quoted lines
>> I don't know: I think
>> 
>> 	cat >expect <<-\EOF &&
>> 	...
>> 	EOF
>> 
>> is pretty readable.  The problem with sticking to
>
> Yeah, I almost mentioned that, but for some reason in the back of my
> mind <<- is not actually portable. Perhaps I am just thinking of the
> fact that perl does not support it.

I seem to remember some language where the here documents would snip some well determined constant amount of whitespace from the enclosed lines. Unfortunately in the shell, that is not the rule: <<- just trims out all the leading tabs.

So when expected output includes leading tabs, it is ugly again.
	q_to_tab <<-\EOF
	Like this:
	Q1. indented line
	Q2. second indented line
	EOF
Previous: Jeff KingNext: Jonathan Nieder
Message 19 of 27 in “Several tests: cd inside subshell instead of around”
  1. Several tests: cd inside subshell instead of aroundJens Lehmann, Sep 6, 2010
  2. Jonathan NiederSep 6, 2010
  3. Jens LehmannSep 6, 2010
  4. 0/7 Re: [PATCH] Several tests: cd inside subshell instead of aroundJonathan Nieder, Sep 7, 2010
  5. 1/7 tests: subshell indentation stylefixJonathan Nieder, Sep 7, 2010
  6. Jonathan NiederSep 7, 2010
  7. 2/7 t1450 (fsck): remove dangling objectsJonathan Nieder, Sep 7, 2010
  8. 3/7 t2105 (gitfile): add missing &&Jonathan Nieder, Sep 7, 2010
  9. Brad KingSep 7, 2010
  10. 4/7 t0004 (unwritable files): simplify error handlingJonathan Nieder, Sep 7, 2010
  11. 5/7 t1302 (core.repositoryversion): style tweaksJonathan Nieder, Sep 7, 2010
  12. Nguyen Thai Ngoc DuySep 7, 2010
  13. 6/7 t1303 (config): style tweaksJonathan Nieder, Sep 7, 2010
  14. Jeff KingSep 7, 2010
  15. Junio C HamanoSep 7, 2010
  16. Jonathan NiederSep 7, 2010
  17. guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)Jonathan Nieder, Sep 7, 2010
  18. Jeff KingSep 7, 2010
  19. Jonathan NiederSep 7, 2010
  20. 7/7 t2016 (checkout -p): use printf for multiline y/n inputJonathan Nieder, Sep 7, 2010
  21. Thomas RastSep 7, 2010
  22. Jonathan NiederSep 7, 2010
  23. Junio C HamanoSep 6, 2010
  24. Jonathan NiederSep 7, 2010
  25. Junio C HamanoSep 7, 2010
  26. Jonathan NiederSep 7, 2010
  27. t1020: Get rid of 'cd "$HERE"' at the start of each testJens Lehmann, Sep 7, 2010

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.