[PATCH 3/3] test: add tests for --profile CLI option

Subject: [PATCH 3/3] test: add tests for --profile CLI option

Date: Sat, 9 May 2026 17:49:54 +0200

To: notmuch@notmuchmail.org

Cc: inwit

From: inwit


Add coverage for the new --profile flag:

  - T035-read-config.sh: lightweight saved-query tests exercising
    both the XDG path and the home fallback path.

  - T055-path-config.sh: XDG+cli-profile variant in the existing
    path-config loop. The setup function exercises --profile for
    config set operations; the NOTMUCH_PROFILE env var is set for
    the remaining loop operations (count, tag, address, dump,
    restore, reindex, new, show, reply, insert, compact, config).

Signed-off-by: inwit <inwit@sindominio.net>
---
 test/T035-read-config.sh | 44 ++++++++++++++++++++++++++++++++++++++++
 test/T055-path-config.sh | 25 ++++++++++++++++++++++-
 2 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/test/T035-read-config.sh b/test/T035-read-config.sh
index ac0f420b..bc057787 100755
--- a/test/T035-read-config.sh
+++ b/test/T035-read-config.sh
@@ -22,6 +22,19 @@ xdg_config () {
     unset NOTMUCH_CONFIG
 }
 
+xdg_config_cli () {
+    local dir
+    local profile=${1:-default}
+    backup_config
+    dir="${HOME}/.config/notmuch/${profile}"
+    rm -rf $dir
+    mkdir -p $dir
+    CONFIG_PATH=$dir/config
+    mv ${NOTMUCH_CONFIG} ${CONFIG_PATH}
+    unset NOTMUCH_CONFIG
+    unset NOTMUCH_PROFILE
+}
+
 restore_config () {
     local test_name=$(basename $0 .sh)
     export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
@@ -473,4 +486,35 @@ output=$(NOTMUCH_NEW --debug)
 restore_config
 test_expect_equal "$output" "Added 1 new message to the database."
 
+test_begin_subtest "count with saved query from config file (xdg+cli-profile)"
+query_name="test${RANDOM}"
+xdg_config_cli work
+notmuch --profile=work count query:$query_name > OUTPUT
+printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
+notmuch --profile=work count query:$query_name >> OUTPUT
+cat <<EOF > EXPECTED
+0
+52
+EOF
+restore_config
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "count with saved query from config file (cli-profile, home fallback)"
+query_name="test${RANDOM}"
+profile_name="p${RANDOM}"
+backup_config
+cp ${NOTMUCH_CONFIG} ${HOME}/.notmuch-config.${profile_name}
+unset NOTMUCH_CONFIG
+unset NOTMUCH_PROFILE
+notmuch --profile=$profile_name count query:$query_name > OUTPUT
+printf "\n[query]\n${query_name} = tag:inbox\n" >> ${HOME}/.notmuch-config.${profile_name}
+notmuch --profile=$profile_name count query:$query_name >> OUTPUT
+rm -f ${HOME}/.notmuch-config.${profile_name}
+cat <<EOF > EXPECTED
+0
+52
+EOF
+restore_config
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 4d1edec0..7d5b2eb9 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -92,6 +92,25 @@ xdg_config () {
     notmuch --config=${CONFIG_PATH} config set database.path
 }
 
+xdg_config_cli () {
+    local profile=${1:-default}
+    local dir
+    backup_config
+    dir="${HOME}/.local/share/notmuch/${profile}"
+    DATABASE_PATH="${dir}"
+    rm -rf $dir
+    mkdir -p $dir
+    dir="${HOME}/.config/notmuch/${profile}"
+    mkdir -p ${dir}
+    CONFIG_PATH=$dir/config
+    mv ${NOTMUCH_CONFIG} $CONFIG_PATH
+    unset NOTMUCH_CONFIG
+    XAPIAN_PATH="${DATABASE_PATH}/xapian"
+    notmuch --profile=$profile config set database.mail_root ${TMP_DIRECTORY}/mail
+    notmuch --profile=$profile config set database.path
+    export NOTMUCH_PROFILE=$profile
+}
+
 mailroot_only_config () {
     local dir
 
@@ -105,7 +124,7 @@ mailroot_only_config () {
     mv mail/.notmuch/xapian $DATABASE_PATH
 }
 
-for config in traditional split XDG XDG+profile symlink home_mail maildir_env mailroot_only; do
+for config in traditional split XDG XDG+profile XDG+cli-profile symlink home_mail maildir_env mailroot_only; do
     #start each set of tests with an known set of messages
     add_email_corpus
 
@@ -126,6 +145,10 @@ for config in traditional split XDG XDG+profile symlink home_mail maildir_env ma
 	    xdg_config ${RANDOM}
 	    mv mail/.notmuch/xapian $DATABASE_PATH
 	    ;;
+	XDG+cli-profile)
+	    xdg_config_cli ${RANDOM}
+	    mv mail/.notmuch/xapian $DATABASE_PATH
+	    ;;
 	symlink)
 	    symlink_config
 	    ;;
-- 
2.53.0

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: