File tree Expand file tree Collapse file tree 4 files changed +63
-5
lines changed Expand file tree Collapse file tree 4 files changed +63
-5
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ defmodule ExUnit.CLIFormatter do
18
18
IO . puts ( "" )
19
19
20
20
config = % {
21
+ dry_run: opts [ :dry_run ] ,
21
22
trace: opts [ :trace ] ,
22
23
colors: colors ( opts ) ,
23
24
width: get_terminal_width ( ) ,
@@ -154,7 +155,16 @@ defmodule ExUnit.CLIFormatter do
154
155
{ :noreply , config }
155
156
end
156
157
157
- def handle_cast ( { :module_finished , % ExUnit.TestModule { state: nil } } , config ) do
158
+ def handle_cast ( { :module_finished , % ExUnit.TestModule { state: nil } = module } , config ) do
159
+ if config . dry_run do
160
+ IO . puts ( "Test dry run:" )
161
+ file_path = Path . relative_to_cwd ( module . file )
162
+
163
+ Enum . each ( module . tests , fn test ->
164
+ IO . puts ( "#{ file_path } :#{ test . tags . line } " )
165
+ end )
166
+ end
167
+
158
168
{ :noreply , config }
159
169
end
160
170
@@ -356,7 +366,11 @@ defmodule ExUnit.CLIFormatter do
356
366
)
357
367
|> if_true (
358
368
config . excluded_counter > 0 ,
359
- & ( & 1 <> " (#{ config . excluded_counter } excluded)" )
369
+ & ( & 1 <> ", (#{ config . excluded_counter } excluded)" )
370
+ )
371
+ |> if_true (
372
+ config . dry_run == true ,
373
+ & ( & 1 <> " (dry run)" )
360
374
)
361
375
362
376
cond do
Original file line number Diff line number Diff line change @@ -88,7 +88,8 @@ defmodule ExUnit.Runner do
88
88
seed: opts [ :seed ] ,
89
89
stats_pid: stats_pid ,
90
90
timeout: opts [ :timeout ] ,
91
- trace: opts [ :trace ]
91
+ trace: opts [ :trace ] ,
92
+ dry_run: opts [ :dry_run ]
92
93
}
93
94
end
94
95
@@ -306,6 +307,10 @@ defmodule ExUnit.Runner do
306
307
{ test_module , [ ] , [ ] }
307
308
end
308
309
310
+ defp run_module_tests ( % { dry_run: true } , test_module , _async? , tests ) do
311
+ { test_module , [ ] , tests }
312
+ end
313
+
309
314
defp run_module_tests ( config , test_module , async? , tests ) do
310
315
Process . put ( @ current_key , test_module )
311
316
% ExUnit.TestModule { name: module , tags: tags , parameters: params } = test_module
Original file line number Diff line number Diff line change @@ -121,6 +121,10 @@ defmodule Mix.Tasks.Test do
121
121
122
122
* `--cover` - runs coverage tool. See "Coverage" section below
123
123
124
+ * `--dry-run` *(since v1.19.0)* - prints which tests would be run based on current options,
125
+ but does not actually run any tests. This combines with all other options
126
+ like `--stale`, `--only`, `--exclude`, and so on.
127
+
124
128
* `--exclude` - excludes tests that match the filter. This option may be given
125
129
several times to apply different filters, such as `--exclude ci --exclude slow`
126
130
@@ -494,7 +498,8 @@ defmodule Mix.Tasks.Test do
494
498
warnings_as_errors: :boolean ,
495
499
profile_require: :string ,
496
500
exit_status: :integer ,
497
- repeat_until_failure: :integer
501
+ repeat_until_failure: :integer ,
502
+ dry_run: :boolean
498
503
]
499
504
500
505
@ cover [ output: "cover" , tool: Mix.Tasks.Test.Coverage ]
@@ -847,7 +852,8 @@ defmodule Mix.Tasks.Test do
847
852
:only_test_ids ,
848
853
:test_location_relative_path ,
849
854
:exit_status ,
850
- :repeat_until_failure
855
+ :repeat_until_failure ,
856
+ :dry_run
851
857
]
852
858
853
859
@ doc false
Original file line number Diff line number Diff line change @@ -716,6 +716,39 @@ defmodule Mix.Tasks.TestTest do
716
716
end
717
717
end
718
718
719
+ describe "--dry-run" do
720
+ test "works with --stale" do
721
+ in_fixture ( "test_stale" , fn ->
722
+ File . write! ( "test/dry_run_test_stale.exs" , """
723
+ defmodule DryRunTest do
724
+ use ExUnit.Case
725
+
726
+ test "new test" do
727
+ assert true
728
+ end
729
+ end
730
+ """ )
731
+
732
+ output = mix ( [ "test" , "--dry-run" , "--stale" ] )
733
+
734
+ assert output =~ "Test dry run:"
735
+ assert output =~ "test/dry_run_test_stale.exs:4"
736
+ assert output =~ "0 tests, 0 failures (dry run)"
737
+ end )
738
+ end
739
+
740
+ test "works with --failed" do
741
+ in_fixture ( "test_failed" , fn ->
742
+ _initial_run = mix ( [ "test" ] )
743
+ output = mix ( [ "test" , "--dry-run" , "--failed" ] )
744
+
745
+ assert output =~ "Test dry run:"
746
+ assert output =~ "test/passing_and_failing_test_failed.exs:5"
747
+ assert output =~ "0 tests, 0 failures (dry run)"
748
+ end )
749
+ end
750
+ end
751
+
719
752
defp receive_until_match ( port , expected , acc ) do
720
753
receive do
721
754
{ ^ port , { :data , output } } ->
You can’t perform that action at this time.
0 commit comments