unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/3] test: initial tests for external commands
Date: Tue, 31 May 2022 08:50:58 -0300	[thread overview]
Message-ID: <20220531115100.2446050-1-david@tethera.net> (raw)

The main goal is to test the setting of NOTMUCH_CONFIG, but also
include a basic sanity test for execing scripts.
---
 test/T405-external.sh | 55 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100755 test/T405-external.sh

diff --git a/test/T405-external.sh b/test/T405-external.sh
new file mode 100755
index 00000000..b121fc72
--- /dev/null
+++ b/test/T405-external.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+test_description='hooks'
+. $(dirname "$0")/test-lib.sh || exit 1
+
+create_echo_script () {
+    local TOKEN="${RANDOM}"
+    mkdir -p ${BIN_DIR}
+    cat <<EOF >"${BIN_DIR}/${1}"
+#!/bin/sh
+echo "${TOKEN}" > ${3}
+EOF
+    chmod +x "${BIN_DIR}/${1}"
+    echo "${TOKEN}" > ${2}
+}
+
+create_printenv_script () {
+    mkdir -p ${BIN_DIR}
+    cat <<EOF >"${BIN_DIR}/${1}"
+#!/bin/sh
+printenv "${2}" > "${3}"
+EOF
+    chmod +x "${BIN_DIR}/${1}"
+}
+
+# add a message to generate mail dir and database
+add_message
+
+BIN_DIR=`pwd`/bin
+PATH=$BIN_DIR:$PATH
+
+test_begin_subtest "'notmuch foo' runs notmuch-foo"
+rm -rf ${BIN_DIR}
+create_echo_script "notmuch-foo" EXPECTED OUTPUT $HOOK_DIR
+notmuch foo
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
+create_printenv_script "notmuch-printenv" NOTMUCH_CONFIG OUTPUT
+
+test_begin_subtest "NOTMUCH_CONFIG is set"
+notmuch printenv
+cat <<EOF > EXPECTED
+${NOTMUCH_CONFIG}
+EOF
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
+test_begin_subtest "NOTMUCH_CONFIG is set by --config"
+test_subtest_known_broken
+cp "${NOTMUCH_CONFIG}" "${NOTMUCH_CONFIG}.alternate"
+cat <<EOF > EXPECTED
+${NOTMUCH_CONFIG}.alternate
+EOF
+notmuch --config "${NOTMUCH_CONFIG}.alternate" printenv
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
+test_done
-- 
2.35.2

             reply	other threads:[~2022-05-31 11:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31 11:50 David Bremner [this message]
2022-05-31 11:50 ` [PATCH 2/3] CLI: pass --config to external commands via NOTMUCH_CONFIG David Bremner
2022-05-31 11:51 ` [PATCH 3/3] CLI: document handling of --config for external commands David Bremner
2022-06-13 10:35 ` [PATCH 1/3] test: initial tests " David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220531115100.2446050-1-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).