From 07539f78257c366536341063c547a63eee6ef160 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 18 Jun 2024 10:50:31 -0400 Subject: [PATCH] Hide logs during test unless a test fails Currently `mix test` prints a slew of logs in the terminal with messages from different tests intermsparsed. Globally enabling capture log hides log messages unless a test fails reducing noise and making it easier to anylse the important (from failed tests) messages. Compiler warnings and a few messages not printed via Logger still show up but its much more readable than before. Ported from: https://git.pleroma.social/pleroma/pleroma/-/commit/3aed111a42472018f01899714305d4f3a5cbc911 --- test/mix/tasks/pleroma/config_test.exs | 1 - test/pleroma/object/fetcher_test.exs | 1 - test/pleroma/user_test.exs | 2 -- .../web/activity_pub/activity_pub_controller_test.exs | 4 ---- test/pleroma/web/activity_pub/relay_test.exs | 1 - .../activity_pub/transmogrifier/announce_handling_test.exs | 2 -- .../activity_pub/transmogrifier/delete_handling_test.exs | 1 - .../web/activity_pub/transmogrifier/note_handling_test.exs | 2 -- test/pleroma/web/activity_pub/transmogrifier_test.exs | 1 - .../web/mastodon_api/controllers/search_controller_test.exs | 1 - .../mastodon_api/controllers/timeline_controller_test.exs | 2 -- test/pleroma/web/push/impl_test.exs | 2 -- test/pleroma/web/web_finger_test.exs | 1 - test/test_helper.exs | 6 +++++- 14 files changed, 5 insertions(+), 22 deletions(-) diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs index 3b09f656b..75c67efb4 100644 --- a/test/mix/tasks/pleroma/config_test.exs +++ b/test/mix/tasks/pleroma/config_test.exs @@ -51,7 +51,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do clear_config(:configurable_from_database, true) end - @tag capture_log: true test "config migration refused when deprecated settings are found" do clear_config([:media_proxy, :whitelist], ["domain_without_scheme.com"]) assert config_records() == [] diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs index 12154cb05..74f2cd31f 100644 --- a/test/pleroma/object/fetcher_test.exs +++ b/test/pleroma/object/fetcher_test.exs @@ -189,7 +189,6 @@ defmodule Pleroma.Object.FetcherTest do :ok end - @tag capture_log: true test "it works when fetching the OP actor errors out" do # Here we simulate a case where the author of the OP can't be read assert {:ok, _} = diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index de71f4b95..90cee1c65 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -814,7 +814,6 @@ defmodule Pleroma.UserTest do assert user == fetched_user end - @tag capture_log: true test "returns nil if no user could be fetched" do {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la") assert fetched_user == "not found nonexistant@social.heldscal.la" @@ -871,7 +870,6 @@ defmodule Pleroma.UserTest do assert orig_user.nickname == "#{orig_user.id}.admin@mastodon.example.org" end - @tag capture_log: true test "it returns the old user if stale, but unfetchable" do a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800) diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index b325bcb9a..4c134c8f2 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -573,7 +573,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert Activity.get_by_ap_id(data["id"]) end - @tag capture_log: true test "it inserts an incoming activity into the database" <> "even if we can't fetch the user but have it in our db", %{conn: conn} do @@ -1074,7 +1073,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert Instances.reachable?(sender_host) end - @tag capture_log: true test "it removes all follower collections but actor's", %{conn: conn} do [actor, recipient] = insert_pair(:user) @@ -1138,7 +1136,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert json_response(ret_conn, 200) end - @tag capture_log: true test "forwarded report", %{conn: conn} do admin = insert(:user, is_admin: true) actor = insert(:user, local: false) @@ -1215,7 +1212,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do ) end - @tag capture_log: true test "forwarded report from mastodon", %{conn: conn} do admin = insert(:user, is_admin: true) actor = insert(:user, local: false) diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs index 920aef9da..99cc2071e 100644 --- a/test/pleroma/web/activity_pub/relay_test.exs +++ b/test/pleroma/web/activity_pub/relay_test.exs @@ -114,7 +114,6 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do assert Relay.publish(activity) == {:error, "Not implemented"} end - @tag capture_log: true test "returns error when activity not public" do activity = insert(:direct_note_activity) assert Relay.publish(activity) == {:error, false} diff --git a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs index 524acddaf..88f42cada 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs @@ -83,7 +83,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do assert(Activity.get_create_by_object_ap_id(data["object"])) end - @tag capture_log: true test "it works for incoming announces with an existing activity" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) @@ -136,7 +135,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do assert object.data["content"] == "this is a private toot" end - @tag capture_log: true test "it rejects incoming announces with an inlined activity from another origin" do Tesla.Mock.mock(fn %{method: :get} -> %Tesla.Env{status: 404, body: ""} diff --git a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs index b7160bf58..e5d6f940a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs @@ -86,7 +86,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do assert match?({:error, _}, Transmogrifier.handle_incoming(data)) end - @tag capture_log: true test "it works for incoming user deletes" do %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin") diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index 16ee31483..6a7bd3a43 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -57,7 +57,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do assert activity == returned_activity end - @tag capture_log: true test "it fetches reply-to activities if we don't have them" do data = File.read!("test/fixtures/mastodon-post-activity.json") @@ -537,7 +536,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do assert modified_object["inReplyTo"] == [] end - @tag capture_log: true test "returns modified object when allowed incoming reply", %{data: data} do object_with_reply = Map.put( diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index dd7977593..1be69317c 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -561,7 +561,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do end) =~ ":valid_uri_scheme" end - @tag capture_log: true test "returns {:ok, %Object{}} for success case" do assert {:ok, %Object{}} = Transmogrifier.get_obj_helper( diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs index 6a0d25058..64364cfb3 100644 --- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs @@ -79,7 +79,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do assert status["id"] == to_string(activity.id) end - @tag capture_log: true test "constructs hashtags from search query", %{conn: conn} do results = conn diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index 3e7b6730c..ccaf17fe4 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -152,7 +152,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do end describe "public" do - @tag capture_log: true test "the public timeline", %{conn: conn} do user = insert(:user) @@ -810,7 +809,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do describe "hashtag" do setup do: oauth_access(["n/a"]) - @tag capture_log: true test "hashtag timeline", %{conn: conn} do following = insert(:user) diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index a40c4ff13..f9936095f 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -67,7 +67,6 @@ defmodule Pleroma.Web.Push.ImplTest do assert Impl.perform(notif) == {:ok, [:ok, :ok]} end - @tag capture_log: true test "returns error if notif does not match " do assert Impl.perform(%{}) == {:error, :unknown_type} end @@ -76,7 +75,6 @@ defmodule Pleroma.Web.Push.ImplTest do assert Impl.push_message(@message, @sub, @api_key, %Subscription{}) == :ok end - @tag capture_log: true test "fail message sending" do assert Impl.push_message( @message, diff --git a/test/pleroma/web/web_finger_test.exs b/test/pleroma/web/web_finger_test.exs index 2af084090..4fc2a8ffa 100644 --- a/test/pleroma/web/web_finger_test.exs +++ b/test/pleroma/web/web_finger_test.exs @@ -190,7 +190,6 @@ defmodule Pleroma.Web.WebFingerTest do end end - @tag capture_log: true test "prevents forgeries" do Tesla.Mock.mock(fn %{url: "https://bad.com/.well-known/webfinger?resource=acct:meanie@bad.com"} -> diff --git a/test/test_helper.exs b/test/test_helper.exs index dafa45099..6dcb87ff6 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -3,7 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-only os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: [] -ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude) + +ExUnit.start( + capture_log: true, + exclude: [:federated, :erratic] ++ os_exclude +) Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)