unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: notmuch@notmuchmail.org
Cc: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,
	Ludovic LANGE <ll-notmuchmail@lange.nom.fr>,
	Tomi Ollila <tomi.ollila@iki.fi>,
	Stefano Zacchiroli <zack@upsilon.cc>
Subject: [PATCH 2/9] test: ruby: refactor test_ruby()
Date: Sat,  1 May 2021 06:59:16 -0500	[thread overview]
Message-ID: <20210501115923.483816-3-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20210501115923.483816-1-felipe.contreras@gmail.com>

There's no point in repeating the same initialization in all the tests.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/T395-ruby.sh | 48 +++++++++++------------------------------------
 1 file changed, 11 insertions(+), 37 deletions(-)

diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh
index fec1f5ef..1d27e191 100755
--- a/test/T395-ruby.sh
+++ b/test/T395-ruby.sh
@@ -9,17 +9,21 @@ fi
 add_email_corpus
 
 test_ruby() {
-    MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
+    (
+	cat <<-\EOF
+	require 'notmuch'
+	$maildir = ENV['MAIL_DIR']
+	if not $maildir then
+	  abort('environment variable MAIL_DIR must be set')
+	end
+	@db = Notmuch::Database.new($maildir)
+	EOF
+	cat
+    ) | MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
 }
 
 test_begin_subtest "compare thread ids"
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
 @q = @db.query('tag:inbox')
 @q.sort = Notmuch::SORT_OLDEST_FIRST
 for t in @q.search_threads do
@@ -31,12 +35,6 @@ test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "compare message ids"
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
 @q = @db.query('tag:inbox')
 @q.sort = Notmuch::SORT_OLDEST_FIRST
 for m in @q.search_messages do
@@ -48,12 +46,6 @@ test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "get non-existent file"
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
 result = @db.find_message_by_filename('i-dont-exist')
 print (result == nil)
 EOF
@@ -61,12 +53,6 @@ test_expect_equal "$(cat OUTPUT)" "true"
 
 test_begin_subtest "count messages"
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
 @q = @db.query('tag:inbox')
 print @q.count_messages(),"\n"
 EOF
@@ -75,12 +61,6 @@ test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "count threads"
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
 @q = @db.query('tag:inbox')
 print @q.count_threads(),"\n"
 EOF
@@ -89,12 +69,6 @@ test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "get all tags"
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
 @t = @db.all_tags()
 for tag in @t do
    print tag,"\n"
-- 
2.31.0

  parent reply	other threads:[~2021-05-01 11:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 11:59 [PATCH 0/9] test: ruby: several cleanups and simplifications Felipe Contreras
2021-05-01 11:59 ` [PATCH 1/9] test: move test_ruby() inside the only client Felipe Contreras
2021-05-02 10:49   ` David Bremner
2021-05-02 18:28     ` Tomi Ollila
2021-05-01 11:59 ` Felipe Contreras [this message]
2021-05-02 10:50   ` [PATCH 2/9] test: ruby: refactor test_ruby() David Bremner
2021-05-01 11:59 ` [PATCH 3/9] test: ruby: simplify MAIL_DIR check Felipe Contreras
2021-05-02 10:51   ` David Bremner
2021-05-01 11:59 ` [PATCH 4/9] test: ruby: simplify MAIL_DIR initialization Felipe Contreras
2021-05-02 10:56   ` David Bremner
2021-05-01 11:59 ` [PATCH 5/9] test: ruby: simplify test_ruby() Felipe Contreras
2021-05-02 11:02   ` David Bremner
2021-05-02 21:53     ` Felipe Contreras
2021-05-01 11:59 ` [PATCH 6/9] test: ruby: use much more standard puts Felipe Contreras
2021-05-02 11:03   ` David Bremner
2021-05-01 11:59 ` [PATCH 7/9] test: ruby: use much more standard Ruby idioms Felipe Contreras
2021-05-02 11:07   ` David Bremner
2021-05-02 19:00     ` Tomi Ollila
2021-05-05 22:29       ` David Bremner
2021-05-06 11:52         ` Felipe Contreras
2021-05-02 22:11     ` Felipe Contreras
2021-05-01 11:59 ` [PATCH 8/9] test: ruby: don't use instance variables Felipe Contreras
2021-05-02 11:08   ` David Bremner
2021-05-01 11:59 ` [PATCH 9/9] test: ruby: simplify output comparison Felipe Contreras
2021-05-02 11:09   ` David Bremner
2021-05-02 11:22 ` [PATCH 0/9] test: ruby: several cleanups and simplifications 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=20210501115923.483816-3-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=dkg@fifthhorseman.net \
    --cc=ll-notmuchmail@lange.nom.fr \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    --cc=zack@upsilon.cc \
    /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).