On Wed, Mar 22, 2017 at 02:49:48PM -0700, Stefan Beller wrote:

> * The syntax of the here-doc was wrong, such that the entire test was
>   sucked into the here-doc, which is why the test succeeded successfully.

As opposed to succeeding unsuccessfully? :)

> * The variable $submodulesha1 was not expanded as it was inside a single
>   quoted string. Use double quote to expand the variable.

Hmm. Sort of. It was inside a non-interpolating here-doc inside a
single-quoted string which was being eval'd. The second half is fine
(the eval adds an extra layer of evaluation).

Your fix:

> +     cat >expect <<-\EOF &&
> +     Execution of '\'"false $submodulesha1"\'' failed in submodule path 
> '\''submodule'\''
> +     EOF

_does_ work, but it does so because it's evaluating $submodulesha1 in
the shell snippet and handing the result off to test_expect_success to
eval. So it would have problems if:

  - that variable contained "\nEOF\n" itself ;)

  - the variable was modified inside the shell snippet.

Neither of those is true, but I think:

  cat >expect <<-EOF &&
  Execution of '\''false $submodulesha1'\'' failed in ...
  EOF

is safer and less surprising. The single-quote handling is unfortunate and
ugly, but necessary to get them into the shell snippet in the first
place. I notice the others tests in this script set up the expect file
outside of a block. You could also do something like:

  sq=\'
  test_expect_success '...' '
        cat >expect <<-EOF
        Execution of ${sq}false $submodulesha1${sq} ...
  '

but I'm not sure if that is any more readable.

-Peff

Reply via email to