On Tue, 17 Jan 2012 14:07:03 +0000, David Edmondson <d...@dme.org> wrote:
> Add a new test function to allow simpler testing of emacs
> functionality.
> 
> `test_emacs_expect_t' takes one argument - a list expression to
> evaluate. The test passes if the expression returns `t', otherwise it
> fails and the output is reported to the tester.
> ---
> 
> Re-worked as Dmitry suggested.
> 
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 7c9ce24..4b05760 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -503,6 +503,39 @@ test_expect_equal_file ()
>      fi
>  }
>  
> +test_emacs_expect_t () {
> +     test "$#" = 1 || error "bug in the test script: not 1 parameter to 
> test_emacs_expect_t"
> +
> +     # Run the test.
> +     if ! test_skip "$test_subtest_name"
> +     then
> +             # We cannot call 'test_emacs' in a subshell, because
> +             # the setting of EMACS_SERVER would not persist
> +             # throughout a sequence of tests, so we use a
> +             # temporary file.
> +             tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
> +             output="$tmp/test_emacs_output.$$"
> +             test_emacs "$1" > "${output}"
> +             result=$(cat "${output}")
> +             rm -f "${output}"
> +     fi
> +
> +     # Restore state after the test.
> +     exec 1>&6 2>&7          # Restore stdout and stderr
> +     inside_subtest=
> +
> +     # Report success/failure.
> +     if ! test_skip "$test_subtest_name"
> +     then
> +             if [ "$result" == t ]

                if [ "$result" = t ]

to be compatible with POSIX and consistent with rest code.

> +             then
> +                     test_ok_ "$test_subtest_name"
> +             else
> +                     test_failure_ "$test_subtest_name" "$(eval printf 
> ${result})"

This added 'eval' made me investigate further... running 

emacsclient --eval '(print (concat "a" "b" "\t" "c" "\n" "z"))'

outputs "ab     c\nz" (tab between 'ab' and 'c', quotes (") around
the whole output and newlines as "\n" (even '\r' is converted)).

If emacs tests run via test_emacs_expect_t wrote their output 
to ${output} directly above code could be much cleaner in many
places. Environment variable could be used for the file name.

Tomi
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to