From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EPOQDADVc2ESAQAAgWs5BA (envelope-from ) for ; Sat, 23 Oct 2021 11:25:20 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id OCgpCADVc2H9FQAAbx9fmQ (envelope-from ) for ; Sat, 23 Oct 2021 09:25:20 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (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 D24B51596E for ; Sat, 23 Oct 2021 11:25:19 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 803D12C1A3; Sat, 23 Oct 2021 05:25:05 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 5D32E2906D for ; Sat, 23 Oct 2021 05:24:58 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 1FA005FC42; Sat, 23 Oct 2021 05:24:57 -0400 (EDT) Received: (nullmailer pid 1403467 invoked by uid 1000); Sat, 23 Oct 2021 09:24:54 -0000 From: David Bremner To: Austin Ray , notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 3/5] lib/open: document expectations for db on error, add tests Date: Sat, 23 Oct 2021 06:24:49 -0300 Message-Id: <20211023092451.1403141-4-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211023092451.1403141-1-david@tethera.net> References: <20211023042225.xt36nzpsukqs6kid@athena> <20211023092451.1403141-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: XSMNNJGULV2PO7JOJFFEH72IXG4OM6N2 X-Message-ID-Hash: XSMNNJGULV2PO7JOJFFEH72IXG4OM6N2 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=1634981119; 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=01rvSxW7p+IEXOascc0gtblA/DShi/xIBwSeIUjIvY4=; b=m90DUoILjSUrpvObE6WshX1QfC5in4IoM9gd8vjJm0IJSfb6tmegRzIBx1VMJZ7E6GRUmX dB7xvk5gOpQ8XbOno+tbB9cLFdLmKCbchOBbIDUFJKs2sJvfOqpxS2XFFE/d9YE3XMevMz +uiJxqvdrBClVKrl0YDQus/gj1wuRuKJclJ1yq2UqkrGehLOd7KycGoe6yvxnXH+0+/AUs Ql1IxAtpzEZWBVrl1Cz0VUgEeqGl8i6un40w7uXzYJUaw4UCl3og9kKEjY1vuuNUS73lPM Vu0cHvyzfDkJr8lvypIPWQM/vakKUk6qlmB4l2mq6prNCgCg0T1ce5GCJz5IlQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634981119; a=rsa-sha256; cv=none; b=sbjwsjTF5gLDC/xwZsSjYLQkEKQASGESGu5muXMIHR65MqY36Zp60p7VCJJ4FGnHwwZrEc rftzmMJOOFwiGF+HLkuKRSIsEZO2sfhGm6PhgRCIZ7TTo+j1WidLfnWduQd66iI198Wg/H 1gMrueN5YDA+y3tTIfKF6lGl6NixyeEDJk+iNiXPCy8cniIdKWxo+t0Ofvlp+4s/wtoPdI XiWlPxzZUgLmiDqDw/dX9HLTepzxemm3qVwFt9jKkERlDKzSRTqDowo3CRZrxcJJ1GAahN HXOAUdtu3VbNfaL6fZMvY1oCuOlWRKNWjdnmZ3Nr/xcLb9G5lx5h3JOjmVsymA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.15 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D24B51596E X-Spam-Score: -1.15 X-Migadu-Scanner: scn0.migadu.com X-TUID: DNmcf9Y7VFZT 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/notmuch.h b/lib/notmuch.h index 074fc682..571b8a87 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 + * 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 ca70642c..b36653bf 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -892,4 +892,46 @@ 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 +test_C ${MAIL_DIR} "/nonexistent" < +int main (int argc, char **argv) { + notmuch_status_t stat; + notmuch_database_t *db = NULL; + + notmuch_status_t st = notmuch_database_create_with_config(argv[1],argv[2], NULL, &db, NULL); + printf("db == NULL: %d\n", 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" +test_C ${MAIL_DIR} < +int main (int argc, char **argv) { + notmuch_status_t stat; + notmuch_database_t *db = NULL; + + notmuch_status_t st = notmuch_database_create_with_config(argv[1], + NULL, NULL, &db, NULL); + printf("db == NULL: %d\n", 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