Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 87E1D429E21 for ; Mon, 23 Jan 2012 08:46:51 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pBajluKryM+E for ; Mon, 23 Jan 2012 08:46:50 -0800 (PST) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8D42F429E54 for ; Mon, 23 Jan 2012 08:46:50 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so1449490bkb.26 for ; Mon, 23 Jan 2012 08:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=/J7gtUIUEWx/WLBdso921rF7rAjsfpOpFWMftpTFbeA=; b=FR/XGsxTcM58eK44lgF4ldJbm1KQ8WlPFvrh/HEfLt2xh7SJ6FoXbm1dsSKVR+Gn1b Qcm/t6w3yhyaAYVIeQU2hAomsqKmqmS52TnRko7HWF2mFaTyxsuVgAI+2MfSLUCzAiqk Mj8YKqTx3RsJmNJUKXEkgp+5BfuGkz7deiWGY= Received: by 10.204.152.219 with SMTP id h27mr3443522bkw.75.1327337209072; Mon, 23 Jan 2012 08:46:49 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id fb7sm17439163bkc.9.2012.01.23.08.46.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jan 2012 08:46:47 -0800 (PST) From: Dmitry Kurochkin To: David Edmondson , notmuch@notmuchmail.org Subject: Re: [PATCH 2/3] test: Add `test_emacs_expect_t'. In-Reply-To: <1326977643-19792-2-git-send-email-dme@dme.org> References: <1326977643-19792-1-git-send-email-dme@dme.org> <1326977643-19792-2-git-send-email-dme@dme.org> User-Agent: Notmuch/0.11+100~gd650abf (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Mon, 23 Jan 2012 20:45:43 +0400 Message-ID: <87lioy2wqw.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jan 2012 16:46:51 -0000 On Thu, 19 Jan 2012 12:54:02 +0000, David Edmondson 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. > --- > > In the interest of moving forward, don't use eval. > > test/README | 8 ++++++++ > test/emacs-test-functions.sh | 9 +++++++++ > test/notmuch-test | 1 + > test/test-lib.el | 9 +++++++++ > test/test-lib.sh | 26 ++++++++++++++++++++++++++ > 5 files changed, 53 insertions(+), 0 deletions(-) > create mode 100755 test/emacs-test-functions.sh > > diff --git a/test/README b/test/README > index bde6db0..9dbe2ee 100644 > --- a/test/README > +++ b/test/README > @@ -189,6 +189,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 > + > + 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 > index 0000000..0e1f9fc > --- /dev/null > +++ b/test/emacs-test-functions.sh > @@ -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 > diff --git a/test/notmuch-test b/test/notmuch-test > index 6a99ae3..d034f99 100755 > --- a/test/notmuch-test > +++ b/test/notmuch-test > @@ -52,6 +52,7 @@ TESTS=" > python > hooks > argument-parsing > + emacs-test-functions.sh > " > TESTS=${NOTMUCH_TESTS:=$TESTS} > > diff --git a/test/test-lib.el b/test/test-lib.el > index 3b817c3..1d51b8d 100644 > --- a/test/test-lib.el > +++ b/test/test-lib.el > @@ -76,3 +76,12 @@ nothing." > > (add-hook-counter 'notmuch-hello-mode-hook) > (add-hook-counter 'notmuch-hello-refresh-hook) > + > +(defmacro notmuch-test-run-test (&rest body) Please consider renaming to `notmuch-hello-run'. > + "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)))) > diff --git a/test/test-lib.sh b/test/test-lib.sh > index 7c9ce24..9cf1b92 100644 > --- a/test/test-lib.sh > +++ b/test/test-lib.sh > @@ -503,6 +503,32 @@ 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 > + test_emacs "(notmuch-test-run-test $1)" >/dev/null > + 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 > + result=$(cat OUTPUT) > + if [ "$result" = t ] > + then > + test_ok_ "$test_subtest_name" > + else > + test_failure_ "$test_subtest_name" "${result}" > + fi > + fi > +} Test_skip function must be called once during the test. Otherwise $test_count is incremented twice, perhaps there are other side effects as well. I think test_emacs_expect_t function must support optional $prereq argument like other test_equal_* functions (e.g. test_expect_equal). After fixing the above comments, test_emacs_expect_t function should look more like test_expect_equal and friends: exec 1>&6 2>&7 # Restore stdout and stderr [4 lines almost identical to test_expect_equal] if ! test_skip "$test_subtest_name" test_emacs ... ... fi Regards, Dmitry > + > NOTMUCH_NEW () > { > notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file' > -- > 1.7.8.3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch