[Patch v4 2/9] test: add support for compiling and running C snippets

Tomi Ollila tomi.ollila at iki.fi
Sat Mar 21 01:51:21 PDT 2015


On Sat, Mar 14 2015, David Bremner <david at tethera.net> wrote:

> This is to limit the copy-pasta involved in running C tests. I decided

Wat kind of spaghetti have you been eating... ;D

> to keep things simple and not try to provide an actual C skeleton.
>
> The setting of LD_LIBRARY_PATH is to force using the built libnotmuch
> rather than any potential system one.
> ---
>  test/README      |  5 +++++
>  test/test-lib.sh | 15 +++++++++++++++
>  2 files changed, 20 insertions(+)
>
> diff --git a/test/README b/test/README
> index 81a1c82..5b40474 100644
> --- a/test/README
> +++ b/test/README
> @@ -84,6 +84,11 @@ the tests in one of the following ways.
>  	TEST_EMACS=my-special-emacs TEST_EMACSCLIENT=my-emacsclient ./emacs
>  	make test TEST_EMACS=my-special-emacs TEST_EMACSCLIENT=my-emacsclient
>  
> +Some tests may require a c compiler. You can choose the name and flags similarly 
> +to with emacs, e.g.
> +
> +     make test TEST_CC=gcc TEST_CFLAGS="-g -O2"
> +     
>  Quiet Execution
>  ---------------
>  
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 133fbe4..c7af003 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -73,6 +73,8 @@ if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \
>  fi
>  TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
>  TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient}
> +TEST_CC=${TEST_CC:-cc}
> +TEST_CFLAGS=${TEST_CFLAGS:-"-g -O0"}
>  
>  # Protect ourselves from common misconfiguration to export
>  # CDPATH into the environment
> @@ -1161,6 +1163,19 @@ test_python() {
>  		| $cmd -
>  }
>  
> +test_C() {

for consistency test_C () {

> +    test_file="test${test_count}.c"
> +    exec_file=${test_file%%.c}

These could be other way around, if not, exec_file=${test_file%.c} (i.e.
only one % is enough).

> +    cat > ${test_file}
> +    export LD_LIBRARY_PATH=${TEST_DIRECTORY}/../lib
> +    ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch
> +    echo "== stdout ==" > OUTPUT.stdout
> +    echo "== stderr ==" > OUTPUT.stderr
> +    ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
> +    cat OUTPUT.stdout OUTPUT.stderr | sed "s,$(pwd),CWD," > OUTPUT

  sed "s,${PWD},CWD," OUTPUT.stdout OUTPUT.stderr > OUTPUT



More information about the notmuch mailing list