]> git.notmuchmail.org Git - notmuch/commitdiff
test: Add `test_emacs_expect_t'.
authorDavid Edmondson <dme@dme.org>
Tue, 24 Jan 2012 16:14:05 +0000 (16:14 +0000)
committerDavid Bremner <bremner@debian.org>
Wed, 25 Jan 2012 11:25:44 +0000 (07:25 -0400)
Add a new test function to allow simpler testing of emacs
functionality.

`test_emacs_expect_t' takes one argument - a lisp expression to
evaluate. The test passes if the expression returns `t', otherwise it
fails and the output is reported to the tester.

test/README
test/emacs-test-functions.sh [new file with mode: 0755]
test/notmuch-test
test/test-lib.el
test/test-lib.sh

index 44ff653aa2bd5b56c73b795ee06341b7d87f7bba..43656a35baf9f9bc5e5d41aca2b65c8e4e763450 100644 (file)
@@ -202,6 +202,14 @@ library for your script to use.
    tests that may run in the same Emacs instance.  Use `let' instead
    so the scope of the changed variables is limited to a single test.
 
+ test_emacs_expect_t <emacs-lisp-expressions>
+
+  This function executes the provided emacs lisp script within
+  emacs in a manner similar to 'test_emacs'. The expressions should
+  return the value `t' to indicate that the test has passed. If the
+  test does not return `t' then it is considered failed and all data
+  returned by the test is reported to the tester.
+
  test_done
 
    Your test script must have test_done at the end.  Its purpose
diff --git a/test/emacs-test-functions.sh b/test/emacs-test-functions.sh
new file mode 100755 (executable)
index 0000000..0e1f9fc
--- /dev/null
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+test_description="emacs test function sanity"
+. test-lib.sh
+
+test_begin_subtest "emacs test function sanity"
+test_emacs_expect_t 't'
+
+test_done
index 6a99ae3f7ad8761231887ca1aabd80d2bfadbddb..d034f9979af283c87f1f76a8aa269c1434d2360f 100755 (executable)
@@ -52,6 +52,7 @@ TESTS="
   python
   hooks
   argument-parsing
+  emacs-test-functions.sh
 "
 TESTS=${NOTMUCH_TESTS:=$TESTS}
 
index 59c586813d45f7f71033a6d7d87f01c62de37e79..96752f0b0e5ad33acd699550db7ef1777b00e804 100644 (file)
@@ -83,3 +83,12 @@ nothing."
 
 (add-hook-counter 'notmuch-hello-mode-hook)
 (add-hook-counter 'notmuch-hello-refresh-hook)
+
+(defmacro notmuch-test-run (&rest body)
+  "Evaluate a BODY of test expressions and output the result."
+  `(with-temp-buffer
+     (let ((result (progn ,@body)))
+       (insert (if (stringp result)
+                  result
+                (prin1-to-string result)))
+       (test-output))))
index 82c686ca074030e86397693775512c764751b690..815832843cd3a3a400bca439965e9a68856975a2 100644 (file)
@@ -503,6 +503,35 @@ test_expect_equal_file ()
     fi
 }
 
+test_emacs_expect_t () {
+       test "$#" = 2 && { prereq=$1; shift; } || prereq=
+       test "$#" = 1 ||
+       error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t"
+
+       # Run the test.
+       if ! test_skip "$test_subtest_name"
+       then
+               test_emacs "(notmuch-test-run $1)" >/dev/null
+
+               # Restore state after the test.
+               exec 1>&6 2>&7          # Restore stdout and stderr
+               inside_subtest=
+
+               # Report success/failure.
+               result=$(cat OUTPUT)
+               if [ "$result" = t ]
+               then
+                       test_ok_ "$test_subtest_name"
+               else
+                       test_failure_ "$test_subtest_name" "${result}"
+               fi
+       else
+               # Restore state after the (non) test.
+               exec 1>&6 2>&7          # Restore stdout and stderr
+               inside_subtest=
+       fi
+}
+
 NOTMUCH_NEW ()
 {
     notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'