Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions elixir/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ defmodule SymphonyElixir.MixProject do
SymphonyElixir.Workspace
]
],
test_ignore_filters: [
"test/support/snapshot_support.exs",
"test/support/test_support.exs"
],
dialyzer: [
plt_add_apps: [:mix]
],
Expand Down
8 changes: 5 additions & 3 deletions elixir/test/mix/tasks/pr_body_check_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ defmodule Mix.Tasks.PrBody.CheckTest do
write_template!(@template)
File.write!("body.md", "#### Context\nContext text.")

assert_raise Mix.Error, ~r/PR body format invalid/, fn ->
Check.run(["lint", "--file", "body.md"])
end
capture_io(:stderr, fn ->
assert_raise Mix.Error, ~r/PR body format invalid/, fn ->
Check.run(["lint", "--file", "body.md"])
end
end)
end)
end

Expand Down
42 changes: 37 additions & 5 deletions elixir/test/mix/tasks/workspace_before_remove_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ defmodule Mix.Tasks.Workspace.BeforeRemoveTest do
exit 0
""",
fn log_path ->
output =
capture_io(fn ->
{output, error_output} =
capture_task_output(fn ->
BeforeRemove.run([])
end)

assert output =~ "Closed PR #101 for branch feature/workpad"
assert error_output =~ "Failed to close PR #102 for branch feature/workpad"

log = File.read!(log_path)

Expand All @@ -103,7 +104,13 @@ defmodule Mix.Tasks.Workspace.BeforeRemoveTest do
with_fake_gh(fn log_path ->
File.write!(log_path, "")

BeforeRemove.run(["--branch", "feature/workpad"])
{output, error_output} =
capture_task_output(fn ->
BeforeRemove.run(["--branch", "feature/workpad"])
end)

assert output =~ "Closed PR #101 for branch feature/workpad"
assert error_output =~ "Failed to close PR #102 for branch feature/workpad"

log = File.read!(log_path)

Expand All @@ -112,12 +119,13 @@ defmodule Mix.Tasks.Workspace.BeforeRemoveTest do
assert log =~ "pr close 101 --repo openai/symphony"
assert log =~ "pr close 102 --repo openai/symphony"

error_output =
capture_io(:stderr, fn ->
{second_output, error_output} =
capture_task_output(fn ->
Mix.Task.reenable("workspace.before_remove")
BeforeRemove.run(["--branch", "feature/workpad"])
end)

assert second_output =~ "Closed PR #101 for branch feature/workpad"
assert error_output =~ "Failed to close PR #102 for branch feature/workpad"
end)
end
Expand Down Expand Up @@ -355,4 +363,28 @@ defmodule Mix.Tasks.Workspace.BeforeRemoveTest do
File.rm_rf!(root)
end
end

defp capture_task_output(fun) do
parent = self()
ref = make_ref()

error_output =
capture_io(:stderr, fn ->
output =
capture_io(fn ->
fun.()
end)

send(parent, {ref, output})
end)

output =
receive do
{^ref, output} -> output
after
1_000 -> flunk("Timed out waiting for captured task output")
end

{output, error_output}
end
end