From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WA6xEMAMdGGKjwAAgWs5BA (envelope-from ) for ; Sat, 23 Oct 2021 15:23:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id AJRGDMAMdGH/LwAAbx9fmQ (envelope-from ) for ; Sat, 23 Oct 2021 13:23:12 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D168B1430A for ; Sat, 23 Oct 2021 15:23:11 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 38CEE2C1F8; Sat, 23 Oct 2021 09:23:01 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 70E2C2C1B0 for ; Sat, 23 Oct 2021 09:22:55 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 430A75FC48; Sat, 23 Oct 2021 09:22:54 -0400 (EDT) Received: (nullmailer pid 1864480 invoked by uid 1000); Sat, 23 Oct 2021 13:22:52 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 3/6] lib/create: document expectations for db on error, add tests Date: Sat, 23 Oct 2021 10:22:35 -0300 Message-Id: <20211023132238.1864400-4-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211023132238.1864400-1-david@tethera.net> References: <20211023132238.1864400-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: SLFSH4XVXPVHTYIMG3A6TUPGI4ZG652U X-Message-ID-Hash: SLFSH4XVXPVHTYIMG3A6TUPGI4ZG652U X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1634995391; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Lxv26xXzH1yKn4O3mO+gXF6xPQO/a7EI1PdR3tpvJPs=; b=uWUe3SkARuLK0AJBjdSS4MEnhn8GhwUbdGHVL33tnw0Zn8C2mjUH/+7LlLqDvvRHraed9p EMTga5BrReeBGubw68yigi6H/VbL+3mtbGwfCTp1tY+qr2widRhyaaQElC3iVbT508c9kB nD6IZm489tdM1zdjMr6QO4jbLE9J89m+fXkhetvfnYLfzZ1PDmAyyhH+YQu+m8plt5WRTc bS5821g3UQiD9K3CbqWe9eCKWkCJQULHBAu4MIJa6C1pnGbUWePVvuicujHtcF/WG0tcBC YjivzbmwqEgO/Wvj9ozsNM7Sx5gMMZe5OtMrx39Y+3p28uhPQW5pEV3dNy4TWQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634995391; a=rsa-sha256; cv=none; b=Drt22YJ5bVAnNf0Is5joq3QYicho6AKW/to9HT7La0yy1G2WCblNTn70CE8RI68ygpAODl Da6YJ1Dsu4I6xBtzDlIqxjZwcUWajvzr196ZAz78kFRX5g9g+z9caKUpoQFwNeXzH/Rype RmF7H4tc5mdDx6LzQAodq82eSXt3ZpmdWJS/WCvm03/CQnbpEiudOOuSH1J4dmF4ZR3JDs dCifTl/os3uWRnnSMROY6/E9+fORdnzzZpb4x/Yj5bJsDOCik8CedhBoqb03hiZpvcx6wC iX2ficO+7CtiauL+GXb50hDizUtJg+FJ6/9waD9SP93JiAgAxHaDilww1jmsFQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.98 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D168B1430A X-Spam-Score: -0.98 X-Migadu-Scanner: scn1.migadu.com X-TUID: IGvnoLkhWbOR It seems sensible to harmonize the behaviour with n_d_open_with_config. In this commit we just assert the desired behaviour. --- lib/notmuch.h | 3 +++ test/T590-libconfig.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/notmuch.h b/lib/notmuch.h index 074fc682..701eb814 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -489,6 +489,9 @@ notmuch_database_load_config (const char *database_path, * * For description of arguments, @see notmuch_database_open_with_config * + * In case of any failure, this function returns an error status and + * sets *database to NULL. + * * @retval NOTMUCH_STATUS_SUCCESS: Successfully created the database. * * @retval NOTMUCH_STATUS_DATABASE_EXISTS: Database already exists, not created diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index a0d70080..becb2821 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -890,4 +890,32 @@ db == NULL: 1 EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "create: database set to null on missing config" +test_subtest_known_broken +cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent" + notmuch_status_t st = notmuch_database_create_with_config(argv[1],argv[2], NULL, &db, NULL); +EOF +cat < EXPECTED +== stdout == +db == NULL: 1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "create: database set to null on missing config (env)" +test_subtest_known_broken +old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} +NOTMUCH_CONFIG="/nonexistent" +cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} + notmuch_status_t st = notmuch_database_create_with_config(argv[1], + NULL, NULL, &db, NULL); +EOF +NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +cat < EXPECTED +== stdout == +db == NULL: 1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.33.0