@@ -5,11 +5,11 @@ defmodule ExDoc.CLITest do
55
66 @ ebin "_build/test/lib/ex_doc/ebin"
77
8- defp run ( args ) do
8+ defp run ( args , generator \\ & { & 1 , & 2 , & 3 } , io_device \\ :stdio ) do
99 # TODO: Use with_io on Elixir v1.13
1010 io =
11- capture_io ( fn ->
12- send ( self ( ) , ExDoc.CLI . main ( args , & { & 1 , & 2 , & 3 } ) )
11+ capture_io ( io_device , fn ->
12+ send ( self ( ) , ExDoc.CLI . main ( args , generator ) )
1313 end )
1414
1515 assert_receive response
@@ -20,115 +20,116 @@ defmodule ExDoc.CLITest do
2020 { [ html , epub ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin ] )
2121
2222 assert html ==
23- { "ExDoc" , "1.2.3" ,
24- [
25- formatter: "html" ,
26- formatters: [ "html" , "epub" ] ,
27- apps: [ :ex_doc ] ,
28- source_beam: @ ebin
29- ] }
23+ { :ok ,
24+ { "ExDoc" , "1.2.3" ,
25+ [
26+ formatter: "html" ,
27+ formatters: [ "html" , "epub" ] ,
28+ apps: [ :ex_doc ] ,
29+ source_beam: @ ebin
30+ ] } }
3031
3132 assert epub ==
32- { "ExDoc" , "1.2.3" ,
33- [
34- formatter: "epub" ,
35- formatters: [ "html" , "epub" ] ,
36- apps: [ :ex_doc ] ,
37- source_beam: @ ebin
38- ] }
33+ { :ok ,
34+ { "ExDoc" , "1.2.3" ,
35+ [
36+ formatter: "epub" ,
37+ formatters: [ "html" , "epub" ] ,
38+ apps: [ :ex_doc ] ,
39+ source_beam: @ ebin
40+ ] } }
3941 end
4042
4143 test "formatter option" do
4244 { [ epub , html ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin , "-f" , "epub" , "-f" , "html" ] )
4345
4446 assert epub ==
45- { "ExDoc" , "1.2.3" ,
46- [
47- formatter: "epub" ,
48- formatters: [ "epub" , "html" ] ,
49- apps: [ :ex_doc ] ,
50- source_beam: @ ebin
51- ] }
47+ { :ok ,
48+ { "ExDoc" , "1.2.3" ,
49+ [
50+ formatter: "epub" ,
51+ formatters: [ "epub" , "html" ] ,
52+ apps: [ :ex_doc ] ,
53+ source_beam: @ ebin
54+ ] } }
5255
5356 assert html ==
54- { "ExDoc" , "1.2.3" ,
55- [
56- formatter: "html" ,
57- formatters: [ "epub" , "html" ] ,
58- apps: [ :ex_doc ] ,
59- source_beam: @ ebin
60- ] }
57+ { :ok ,
58+ { "ExDoc" , "1.2.3" ,
59+ [
60+ formatter: "html" ,
61+ formatters: [ "epub" , "html" ] ,
62+ apps: [ :ex_doc ] ,
63+ source_beam: @ ebin
64+ ] } }
6165 end
6266
6367 test "version" do
6468 { _ , io } = run ( [ "--version" ] )
65- assert io == "ExDoc v#{ ExDoc . version ( ) } \n "
69+ assert io =~ "ExDoc v#{ ExDoc . version ( ) } \n "
6670
6771 { _ , io } = run ( [ "--version" ] )
68- assert io == "ExDoc v#{ ExDoc . version ( ) } \n "
72+ assert io =~ "ExDoc v#{ ExDoc . version ( ) } \n "
6973 end
7074
7175 describe "--warnings-as-errors" do
7276 @ describetag :warnings
7377
74- test "exits with code 0 when no warnings" do
78+ test "exits with 0 when there are warnings and --warnings-as-errors flag is not set " do
7579 ExDoc.Utils . unset_warned ( )
7680
77- { [ html , epub ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin , "--warnings-as-errors" ] )
78-
79- assert html ==
80- { "ExDoc" , "1.2.3" ,
81- [
82- formatter: "html" ,
83- formatters: [ "html" , "epub" ] ,
84- apps: [ :ex_doc ] ,
85- source_beam: @ ebin ,
86- warnings_as_errors: true
87- ] }
88-
89- assert epub ==
90- { "ExDoc" , "1.2.3" ,
91- [
92- formatter: "epub" ,
93- formatters: [ "html" , "epub" ] ,
94- apps: [ :ex_doc ] ,
95- source_beam: @ ebin ,
96- warnings_as_errors: true
97- ] }
81+ Mix.Project . in_project ( :single , "test/fixtures/single" , fn _mod ->
82+ source_beam = "_build/test/lib/single/ebin"
83+
84+ fun = fn ->
85+ run (
86+ [ "Single" , "1.2.3" , source_beam , "--formatter=html" ] ,
87+ & ExDoc . generate_docs / 3 ,
88+ :stderr
89+ )
90+ end
91+
92+ { [ _html ] , io } = fun . ( )
93+
94+ assert io =~
95+ ~s| documentation references function \" Single.bar/0\" but it is undefined or private|
96+
97+ # TODO: remove check when we require Elixir v1.16
98+ if Version . match? ( System . version ( ) , ">= 1.16.0-rc" ) do
99+ assert io =~ ~S| moduledoc `Single.bar/0`|
100+ assert io =~ ~S| doc `Single.bar/0`|
101+ else
102+ assert io =~ ~R| lib/single\.ex:\d+: Single \(module\)|
103+ assert io =~ ~R| lib/single\.ex:\d+: Single\.foo/0|
104+ end
105+ end )
98106 end
99107
100- test "exits with 1 when there is a warning " do
101- ExDoc.Utils . set_warned ( )
108+ test "exits with 1 when there are warnings with --warnings-as-errors flag " do
109+ ExDoc.Utils . unset_warned ( )
102110
103- fun = fn ->
104- run ( [ "ExDoc" , "1.2.3" , @ ebin , "--warnings-as-errors" ] )
105- end
111+ Mix.Project . in_project ( :single , "test/fixtures/single" , fn _mod ->
112+ source_beam = "_build/test/lib/single/ebin"
106113
107- io =
108- capture_io ( :stderr , fn ->
109- assert catch_exit ( fun . ( ) ) == { :shutdown , 1 }
110- end )
114+ fun = fn ->
115+ run (
116+ [ "Single" , "1.2.3" , source_beam , "--formatter=html" , "--warnings-as-errors" ] ,
117+ & ExDoc . generate_docs / 3 ,
118+ :stderr
119+ )
120+ end
111121
112- assert io =~
113- "Doc generation failed due to warnings while using the --warnings-as-errors option\n "
114- end
122+ # fun.()
115123
116- test "exits with 1 when there are multiple warnings" do
117- ExDoc.Utils . set_warned ( )
118- ExDoc.Utils . set_warned ( )
119- ExDoc.Utils . set_warned ( )
124+ io =
125+ capture_io ( :stderr , fn ->
126+ assert catch_exit ( fun . ( ) ) == { :shutdown , 1 }
127+ end )
120128
121- fun = fn ->
122- run ( [ "ExDoc" , "1.2.3" , @ ebin , "--warnings-as-errors" ] )
123- end
124-
125- io =
126- capture_io ( :stderr , fn ->
127- assert catch_exit ( fun . ( ) ) == { :shutdown , 1 }
128- end )
129-
130- assert io =~
131- "Doc generation failed due to warnings while using the --warnings-as-errors option\n "
129+ assert io =~
130+ "Documents have been generated, but generation for html format failed due to warnings " <>
131+ "while using the --warnings-as-errors option."
132+ end )
132133 end
133134 end
134135
@@ -156,7 +157,7 @@ defmodule ExDoc.CLITest do
156157 --canonical http://example.com/project
157158 )
158159
159- { [ { project , version , opts } ] , _io } = run ( args )
160+ { [ { :ok , { project , version , opts } } ] , _io } = run ( args )
160161 assert project == "ExDoc"
161162 assert version == "1.2.3"
162163
@@ -187,7 +188,7 @@ defmodule ExDoc.CLITest do
187188 test "loading" do
188189 File . write! ( "test.exs" , ~s( [extras: ["README.md"], formatters: ["html"]]) )
189190
190- { [ { project , version , opts } ] , _io } =
191+ { [ { :ok , { project , version , opts } } ] , _io } =
191192 run ( [ "ExDoc" , "--extra-section" , "Guides" , "1.2.3" , @ ebin , "-c" , "test.exs" ] )
192193
193194 assert project == "ExDoc"
@@ -208,7 +209,7 @@ defmodule ExDoc.CLITest do
208209 test "switches take precedence over config" do
209210 File . write! ( "test.exs" , ~s( [logo: "config_logo.png", formatters: ["html"]]) )
210211
211- { [ { project , version , opts } ] , _io } =
212+ { [ { :ok , { project , version , opts } } ] , _io } =
212213 run ( [
213214 "ExDoc" ,
214215 "--logo" ,
@@ -254,7 +255,8 @@ defmodule ExDoc.CLITest do
254255 test "loading" do
255256 File . write! ( "test.config" , ~s( {extras, [<<"README.md">>]}. {formatters, [<<"html">>]}.) )
256257
257- { [ { project , version , opts } ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin , "-c" , "test.config" ] )
258+ { [ { :ok , { project , version , opts } } ] , _io } =
259+ run ( [ "ExDoc" , "1.2.3" , @ ebin , "-c" , "test.config" ] )
258260
259261 assert project == "ExDoc"
260262 assert version == "1.2.3"
0 commit comments