From c46aaa181d353578bcd4b3f62e46a5b7b3368f26 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Wed, 25 Mar 2015 09:19:40 +2000 Subject: [PATCH] [Patch v5 2/8] test: add support for compiling and running C snippets --- 20/dfe9796f410399a1ab70563a17a0f7c5a7d532 | 112 ++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 20/dfe9796f410399a1ab70563a17a0f7c5a7d532 diff --git a/20/dfe9796f410399a1ab70563a17a0f7c5a7d532 b/20/dfe9796f410399a1ab70563a17a0f7c5a7d532 new file mode 100644 index 000000000..29ed98e47 --- /dev/null +++ b/20/dfe9796f410399a1ab70563a17a0f7c5a7d532 @@ -0,0 +1,112 @@ +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 58538429E2E + for ; Tue, 24 Mar 2015 06:22:03 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 Lud7isxwi-85 for ; + Tue, 24 Mar 2015 06:22:00 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8ADE4429E35 + for ; Tue, 24 Mar 2015 06:21:57 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YaOlY-0000q8-Mo; Tue, 24 Mar 2015 13:21:08 +0000 +Received: (nullmailer pid 32630 invoked by uid 1000); Tue, 24 Mar 2015 + 13:19:47 -0000 +From: David Bremner +To: David Bremner , notmuch@notmuchmail.org +Subject: [Patch v5 2/8] test: add support for compiling and running C snippets +Date: Tue, 24 Mar 2015 09:19:40 -0400 +Message-Id: <1427203186-32194-2-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1427203186-32194-1-git-send-email-david@tethera.net> +References: <1426352554-4383-10-git-send-email-david@tethera.net> + <1427203186-32194-1-git-send-email-david@tethera.net> +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: Tue, 24 Mar 2015 13:22:03 -0000 + +This is to limit the copy-pasta involved in running C tests. I decided +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..fdb84ea 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 () { ++ exec_file="test${test_count}" ++ test_file="${exec_file}.c" ++ 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 -ltalloc ++ echo "== stdout ==" > OUTPUT.stdout ++ echo "== stderr ==" > OUTPUT.stderr ++ ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr ++ sed "s,$(pwd),CWD," OUTPUT.stdout OUTPUT.stderr > OUTPUT ++} ++ ++ + # Creates a script that counts how much time it is executed and calls + # notmuch. $notmuch_counter_command is set to the path to the + # generated script. Use notmuch_counter_value() function to get the +-- +2.1.4 + -- 2.26.2