Skip to content

Commit 2d1c7d4

Browse files
authored
chore: Cleanup Test Output (#366)
1 parent bc0cb6b commit 2d1c7d4

File tree

3 files changed

+52
-47
lines changed

3 files changed

+52
-47
lines changed

lib/migration_generator/migration_generator.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ defmodule AshPostgres.MigrationGenerator do
379379

380380
operations ->
381381
if opts.check do
382-
IO.puts("""
382+
Mix.shell().error("""
383383
Migrations would have been generated, but the --check flag was provided.
384384
385385
To see what migration would have been generated, run with the `--dry-run`
@@ -1028,7 +1028,7 @@ defmodule AshPostgres.MigrationGenerator do
10281028
end
10291029
rescue
10301030
exception ->
1031-
IO.puts("""
1031+
Mix.shell().error("""
10321032
Exception while formatting:
10331033
10341034
#{inspect(exception)}

test/migration_generator_test.exs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ defmodule AshPostgres.MigrationGeneratorTest do
44

55
import ExUnit.CaptureLog
66

7-
defmacrop defposts(mod \\ Post, do: body) do
7+
setup do
8+
current_shell = Mix.shell()
9+
10+
:ok = Mix.shell(Mix.Shell.Process)
11+
12+
on_exit(fn ->
13+
Mix.shell(current_shell)
14+
end)
15+
end
16+
17+
defmacrop defresource(mod, do: body) do
818
quote do
919
Code.compiler_options(ignore_module_conflict: true)
1020

@@ -13,6 +23,16 @@ defmodule AshPostgres.MigrationGeneratorTest do
1323
domain: nil,
1424
data_layer: AshPostgres.DataLayer
1525

26+
unquote(body)
27+
end
28+
29+
Code.compiler_options(ignore_module_conflict: false)
30+
end
31+
end
32+
33+
defmacrop defposts(mod \\ Post, do: body) do
34+
quote do
35+
defresource unquote(mod) do
1636
postgres do
1737
table "posts"
1838
repo(AshPostgres.TestRepo)
@@ -30,8 +50,23 @@ defmodule AshPostgres.MigrationGeneratorTest do
3050

3151
unquote(body)
3252
end
53+
end
54+
end
3355

34-
Code.compiler_options(ignore_module_conflict: false)
56+
defmacrop defcomments(mod \\ Comment, do: body) do
57+
quote do
58+
defresource unquote(mod) do
59+
postgres do
60+
table "comments"
61+
repo(AshPostgres.TestRepo)
62+
end
63+
64+
actions do
65+
defaults([:create, :read, :update, :destroy])
66+
end
67+
68+
unquote(body)
69+
end
3570
end
3671
end
3772

@@ -108,8 +143,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
108143

109144
defdomain([Post])
110145

111-
Mix.shell(Mix.Shell.Process)
112-
113146
AshPostgres.MigrationGenerator.generate(Domain,
114147
snapshot_path: "test_snapshots_path",
115148
migration_path: "test_migration_path",
@@ -208,8 +241,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
208241

209242
defdomain([Post])
210243

211-
Mix.shell(Mix.Shell.Process)
212-
213244
{:ok, _} =
214245
Ecto.Adapters.SQL.query(
215246
AshPostgres.TestRepo,
@@ -291,7 +322,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
291322
end
292323

293324
defdomain([Post])
294-
Mix.shell(Mix.Shell.Process)
295325

296326
AshPostgres.MigrationGenerator.generate(Domain,
297327
snapshot_path: "test_snapshots_path",
@@ -336,7 +366,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
336366
end
337367

338368
defdomain([Post])
339-
Mix.shell(Mix.Shell.Process)
340369

341370
AshPostgres.MigrationGenerator.generate(Domain,
342371
snapshot_path: "test_snapshots_path",
@@ -378,8 +407,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
378407

379408
defdomain([Post])
380409

381-
Mix.shell(Mix.Shell.Process)
382-
383410
AshPostgres.MigrationGenerator.generate(Domain,
384411
snapshot_path: "test_snapshots_path",
385412
migration_path: "test_migration_path",
@@ -470,8 +497,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
470497

471498
defdomain([Post])
472499

473-
Mix.shell(Mix.Shell.Process)
474-
475500
AshPostgres.MigrationGenerator.generate(Domain,
476501
snapshot_path: "test_snapshots_path",
477502
migration_path: "test_migration_path",
@@ -833,8 +858,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
833858

834859
defdomain([Post])
835860

836-
Mix.shell(Mix.Shell.Process)
837-
838861
AshPostgres.MigrationGenerator.generate(Domain,
839862
snapshot_path: "test_snapshots_path",
840863
migration_path: "test_migration_path",
@@ -1635,11 +1658,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
16351658
File.rm_rf!("test_migration_path")
16361659
end)
16371660

1638-
defmodule Comment do
1639-
use Ash.Resource,
1640-
domain: nil,
1641-
data_layer: AshPostgres.DataLayer
1642-
1661+
defcomments do
16431662
postgres do
16441663
polymorphic?(true)
16451664
repo(AshPostgres.TestRepo)
@@ -1832,16 +1851,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
18321851
end
18331852
end
18341853

1835-
defmodule Comment do
1836-
use Ash.Resource,
1837-
domain: nil,
1838-
data_layer: AshPostgres.DataLayer
1839-
1840-
postgres do
1841-
table "comments"
1842-
repo AshPostgres.TestRepo
1843-
end
1844-
1854+
defcomments do
18451855
attributes do
18461856
uuid_primary_key(:id)
18471857
end
@@ -1855,8 +1865,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
18551865

18561866
defdomain([Post, Comment])
18571867

1858-
Mix.shell(Mix.Shell.Process)
1859-
18601868
AshPostgres.MigrationGenerator.generate(Domain,
18611869
snapshot_path: "test_snapshots_path",
18621870
migration_path: "test_migration_path",
@@ -1881,16 +1889,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
18811889
end
18821890
end
18831891

1884-
defmodule Comment do
1885-
use Ash.Resource,
1886-
domain: nil,
1887-
data_layer: AshPostgres.DataLayer
1888-
1889-
postgres do
1890-
table "comments"
1891-
repo AshPostgres.TestRepo
1892-
end
1893-
1892+
defcomments do
18941893
attributes do
18951894
uuid_primary_key(:id)
18961895
end

test/mix_squash_snapshots_test.exs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ defmodule AshPostgres.MixSquashSnapshotsTest do
22
use AshPostgres.RepoCase, async: false
33
@moduletag :migration
44

5+
setup do
6+
current_shell = Mix.shell()
7+
8+
:ok = Mix.shell(Mix.Shell.Process)
9+
10+
on_exit(fn ->
11+
Mix.shell(current_shell)
12+
end)
13+
end
14+
515
defmacrop defposts(mod \\ Post, do: body) do
616
quote do
717
Code.compiler_options(ignore_module_conflict: true)
@@ -67,8 +77,6 @@ defmodule AshPostgres.MixSquashSnapshotsTest do
6777
File.rm_rf!("test_migration_path")
6878
end)
6979

70-
Mix.shell(Mix.Shell.Process)
71-
7280
defposts do
7381
identities do
7482
identity(:title, [:title])
@@ -154,8 +162,6 @@ defmodule AshPostgres.MixSquashSnapshotsTest do
154162
File.rm_rf!("test_migration_path")
155163
end)
156164

157-
Mix.shell(Mix.Shell.Process)
158-
159165
defposts do
160166
identities do
161167
identity(:title, [:title])

0 commit comments

Comments
 (0)