From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 85BF12D46AF; Sat, 28 Nov 2026 18:37:13 +1100 (AEDT) Date: Sat, 28 Nov 2026 18:37:15 +1100 To: sup-commits@supmua.dev Subject: [sup.git] 02/02: tests: avoid Redwood::start MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179585143333.302910.18345502445563611855@bl2.djc.id.au> References: <179585143333.302910.18345502445563611855@bl2.djc.id.au> Thread-Index: AQAAEjRW9DBx9Y9ySomFNFlQQYMSYw== X-Git-Host: bl2.djc.id.au X-Git-Repo: sup.git X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: cc6011601cdb37888718a9bd4188287455fb7425 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261128073713.85BF12D46AF@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch develop: https://supmua.dev/git/sup/commit/cc6011601cdb37888718a9bd4188287455fb7425.html commit cc6011601cdb37888718a9bd4188287455fb7425 Author: Dan Callaghan 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 = < 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