From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 02/02: tests: avoid Redwood::start
Date: Sat, 28 Nov 2026 18:37:15 +1100 [thread overview]
Message-ID: <20261128073713.85BF12D46AF@bl2.djc.id.au> (raw)
In-Reply-To: <179585143333.302910.18345502445563611855@bl2.djc.id.au>
New commit on branch develop:
https://supmua.dev/git/sup/commit/cc6011601cdb37888718a9bd4188287455fb7425.html
commit cc6011601cdb37888718a9bd4188287455fb7425
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 28 18:34:23 2026 +1100
tests: avoid Redwood::start
Calling Redwood::start meant that some parts of the Sup code would be
initialised from the user's real ~/.sup, which made their behaviour
sensitive to the user's config. Worse still, the tests would write
~/.sup/config.yaml if it was missing due to Redwood::load_config.
Avoid Redwood::start in all tests, in favour of explicitly initialising
whichever Manager classes are needed pointing to temp dirs.
Also add a guard in test_helper to try and ensure nothing leaks into or
out of the real ~/.sup in future.
---
test/integration/test_draft.rb | 12 ++++++++----
test/integration/test_index.rb | 10 +++++++---
test/integration/test_maildir.rb | 11 +++++++----
test/integration/test_mbox.rb | 10 +++++++---
test/test_helper.rb | 11 +++++++++++
test/unit/test_index.rb | 5 ++++-
test/unit/test_thread_view_mode.rb | 12 +++++++++---
7 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/test/integration/test_draft.rb b/test/integration/test_draft.rb
index 4d176894..201306e9 100644
--- a/test/integration/test_draft.rb
+++ b/test/integration/test_draft.rb
@@ -1,14 +1,20 @@
-require "sup"
require "test_helper"
+require "sup"
class TestDraft < Minitest::Test
include Redwood
def setup
@path = Dir.mktmpdir
- start
+ $config = { :stem_language => "english" }
Logger.remove_sink $stderr
@draft_dir = File.join @path, "drafts"
+ HookManager.init File.join(@path, "hooks")
+ UpdateManager.init
+ SourceManager.init
+ PollManager.init
+ LabelManager.init File.join(@path, "labels.txt")
+ DraftManager.init @draft_dir
@test_message_1 = <<EOS
From: Some Person <someone@example.invalid>
To:
@@ -20,10 +26,8 @@ Message-ID: <123@example.invalid>
My incomplete message
EOS
- DraftManager.instance.instance_eval "@dir = '#{@draft_dir}'"
Index.init @path
Index.load
- SourceManager.instance.instance_eval "@sources = {}"
@draft_source = DraftManager.new_source
SourceManager.add_source @draft_source
end
diff --git a/test/integration/test_index.rb b/test/integration/test_index.rb
index 6dbeb59d..b64c5d3b 100644
--- a/test/integration/test_index.rb
+++ b/test/integration/test_index.rb
@@ -1,5 +1,5 @@
-require "sup"
require "test_helper"
+require "sup"
class TestIndexIntegration < Minitest::Test
include Redwood
@@ -39,11 +39,15 @@ EOS
end
def start_sup_and_add_source source
- start
+ $config = { :stem_language => "english" }
Logger.remove_sink $stderr
+ HookManager.init File.join(@path, "hooks")
+ UpdateManager.init
+ SourceManager.init
+ PollManager.init
+ LabelManager.init File.join(@path, "labels.txt")
Index.init @path
Index.load
- SourceManager.instance.instance_eval '@sources = {}'
SourceManager.instance.add_source source
PollManager.poll_from source
Index.save_index
diff --git a/test/integration/test_maildir.rb b/test/integration/test_maildir.rb
index 1f734983..6ac8330a 100644
--- a/test/integration/test_maildir.rb
+++ b/test/integration/test_maildir.rb
@@ -1,5 +1,5 @@
-require "sup"
require "test_helper"
+require "sup"
class TestMaildir < Minitest::Test
@@ -40,11 +40,15 @@ EOS
end
def start_sup_and_add_source(source)
- start
+ $config = { :stem_language => "english" }
Logger.remove_sink $stderr
+ HookManager.init File.join(@path, "hooks")
+ UpdateManager.init
+ SourceManager.init
+ PollManager.init
+ LabelManager.init File.join(@path, "labels.txt")
Index.init @path
Index.load
- SourceManager.instance.instance_eval '@sources = {}'
SourceManager.instance.add_source source
PollManager.poll_from source
Index.save_index
@@ -91,4 +95,3 @@ EOS
assert_equal fallback_date, messages_in_index.first.date
end
end
-
diff --git a/test/integration/test_mbox.rb b/test/integration/test_mbox.rb
index c80f7b81..739acf5c 100644
--- a/test/integration/test_mbox.rb
+++ b/test/integration/test_mbox.rb
@@ -1,5 +1,5 @@
-require "sup"
require "test_helper"
+require "sup"
class TestMbox < Minitest::Test
@@ -33,11 +33,15 @@ EOS
end
def start_sup_and_add_source(source)
- start
+ $config = { :stem_language => "english" }
Logger.remove_sink $stderr
+ HookManager.init File.join(@path, "hooks")
+ UpdateManager.init
+ SourceManager.init
+ PollManager.init
+ LabelManager.init File.join(@path, "labels.txt")
Index.init @path
Index.load
- SourceManager.instance.instance_eval '@sources = {}'
SourceManager.instance.add_source source
PollManager.poll_from source
Index.save_index
diff --git a/test/test_helper.rb b/test/test_helper.rb
index d331781a..35d3295c 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,6 +1,8 @@
require "rubygems" rescue nil
require 'minitest/autorun'
require "rr"
+require "tmpdir"
+require "fileutils"
def fixture_path(filename)
File.expand_path("../fixtures/#{filename}", __FILE__)
@@ -11,3 +13,12 @@ def fixture_contents(filename)
File.open(fixture_path(filename)) { |io| file = io.read }
file
end
+
+## Set SUP_BASE to an empty temp dir, so that tests do not accidentally touch ~/.sup.
+## This means test_helper must be require'd before sup.
+if defined? Redwood::BASE_DIR
+ abort "test_helper must be required before sup"
+end
+test_sup_base = Dir.mktmpdir "sup-base-for-tests"
+ENV["SUP_BASE"] = test_sup_base
+Minitest.after_run { FileUtils.rm_rf test_sup_base }
diff --git a/test/unit/test_index.rb b/test/unit/test_index.rb
index 08221aa2..ad084985 100644
--- a/test/unit/test_index.rb
+++ b/test/unit/test_index.rb
@@ -6,8 +6,11 @@ require "sup"
class TestIndex < Minitest::Test
def setup
@path = Dir.mktmpdir
- Redwood::start
+ $config = { :stem_language => "english" }
Redwood::Logger.remove_sink $stderr
+ Redwood::HookManager.init File.join(@path, "hooks")
+ Redwood::SearchManager.init File.join(@path, "searches.txt")
+ Redwood::SourceManager.init
Redwood::Index.init @path
Redwood::Index.load
end
diff --git a/test/unit/test_thread_view_mode.rb b/test/unit/test_thread_view_mode.rb
index 4c8ae839..ad7edcb8 100644
--- a/test/unit/test_thread_view_mode.rb
+++ b/test/unit/test_thread_view_mode.rb
@@ -1,6 +1,6 @@
+require "test_helper"
require "dummy_buffer"
require "dummy_source"
-require "test_helper"
require "sup"
@@ -11,18 +11,24 @@ class TestThreadViewMode < Minitest::Test
$config = {
:indent_spaces => 2,
:thread_by_subject => false,
+ :stem_language => "english",
+ :default_attachment_save_dir => "",
}
@path = Dir.mktmpdir
@out = File.open File::NULL, "w"
@inp = File.open File::NULL, "r"
@screen = Ncurses.newterm "dumb", @out, @inp
BufferManager.init
- Redwood::start
Logger.remove_sink $stderr
+ HookManager.init File.join(@path, "hooks")
+ UpdateManager.init
+ SourceManager.init
+ PollManager.init
+ LabelManager.init File.join(@path, "labels.txt")
+ ContactManager.init File.join(@path, "contacts.txt")
Index.init File.join(@path, "xapian")
Index.load
@source = DummySource.new("sup-test://test_thread_view_mode")
- SourceManager.instance.instance_eval '@sources = {}'
SourceManager.instance.add_source @source
end
prev parent reply other threads:[~2026-11-28 7:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 7:37 [sup.git] branch develop updated (53f07beb -> cc601160) Dan Callaghan
2026-11-28 7:37 ` [sup.git] 01/02: store HookContext closures on the instance not the class Dan Callaghan
2026-11-28 7:37 ` Dan Callaghan [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128073713.85BF12D46AF@bl2.djc.id.au \
--to=dan@bl2.djc.id.au \
--cc=djc@djc.id.au \
--cc=sup-commits@supmua.dev \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox