]> git.ipfire.org Git - thirdparty/automake.git/commit
tests: better way to compare lists in Makefile rules
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 6 Feb 2012 14:48:30 +0000 (15:48 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 8 Feb 2012 09:04:19 +0000 (10:04 +0100)
commit96401cb96cb4494023c59850d9f6a2912df22c24
treeacbe647e615eced80b901a59d2b12d36c4eb2d3c
parent5066c1b5019b7de419a7b4703c26cb79ee9c713d
tests: better way to compare lists in Makefile rules

With this commit, we introduce a new helper shell script for use
in the testsuite, which is meant to allow the test cases to easily
check whether two whitespace-separated lists are equal; this ability
is particularly useful to check for equality of the contents of make
variables that are expected to contain multiple whitespace-separated
words, and are defined through line continuations (or are rewritten
by automake in this way), or that contain expansion of potentially
empty variables.

Before this change, a test checking that an usage like this one:

  VAR = valA
  if COND1
    VAR += val1 # com1
  endif COND1
  VAR += valC

worked as expected, couldn't use rules like:

  ## Doesn't work because $(VAR) expands to multiple words
  verify:
      test $(VAR) = "valA val1 valC"

nor like:

  ## Doesn't work because the final expansion of $(VAR) contains
  ## repeated contiguous whitespace characters (it actually
  ## equals "valA val1  valC", not "valA val1 valC"), and this
  ## is an internal detail which might change and which we don't
  ## want to explicitly rely on.
  verify:
      test "$(VAR)" = "valA val1 valC"

Instead, we had to rely on cumbersome workaround such as:

  ## This works, but is ugly.
  verify:
      test "`echo $(VAR)`" = "valA val1 valC"

or:

  ## This works, but is even uglier.
  verify:
      echo BEG: $(VAR) :END | grep "BEG: valA val1 valC :END"

Now, with the help of the new 'is' script, we can perform such a
check in a clearer and more straightforward way, as in:

  ## Works, and reads clearly.
  verify:
      is $(VAR) == valA val1 valC

* tests/is: New helper shell script, telling whether two whitespace
separated lists are equal.
* Makefile.am (EXTRA_DIST): Add it.
* tests/colneq2.test: Use the new helper script, and accordingly
get rid of older, more cumbersome idioms.
* tests/cond11.test: Likewise.
* tests/cond16.test: Likewise.
* tests/cond18.test: Likewise.
* tests/cond22.test: Likewise.
* tests/cond31.test: Likewise.
* tests/cond38.test: Likewise.
* tests/test-logs-repeated.test: Likewise.
* tests/objext-pr10128.test: Likewise.
* tests/programs-primary-rewritten.test: Likewise.
* tests/substre2.test: Likewise.  Also ...
(configure.in, Makefile.am): Add a couple of hack to avoid having
to require (and run) a C compiler; accordingly ...
($required): ... remove this.
* tests/exeext4.test: Likewise.
* tests/substref.test: Likewise.  Also ...
(hello.c): Use ": >" rather than "cat <<EOF" to generate it,
since it's meant to be empty anyway.
* tests/cond4.test: Use the new helper script, and accordingly
get rid of older, more cumbersome idioms.  Avoid some unnecessary
uses of "make -e" since we are at it.
* tests/cond19.test: Likewise.
* tests/cond32.test: Likewise.
* tests/cond6.test: Use the new helper script, and accordingly
move some checks in the Makefile.am.
Avoid unnecessary execution of automake remake rules by manually
"touching" aclocal.m4
20 files changed:
tests/Makefile.am
tests/colneq2.test
tests/comment8.test
tests/cond11.test
tests/cond16.test
tests/cond18.test
tests/cond19.test
tests/cond22.test
tests/cond31.test
tests/cond32.test
tests/cond38.test
tests/cond4.test
tests/cond6.test
tests/exeext4.test
tests/is [new file with mode: 0755]
tests/objext-pr10128.test
tests/programs-primary-rewritten.test
tests/substre2.test
tests/substref.test
tests/test-logs-repeated.test