@@ -5,11 +5,11 @@ defmodule ExDoc.CLITest do
5
5
6
6
@ ebin "_build/test/lib/ex_doc/ebin"
7
7
8
- defp run ( args ) do
8
+ defp run ( args , generator \\ & { & 1 , & 2 , & 3 } , io_device \\ :stdio ) do
9
9
# TODO: Use with_io on Elixir v1.13
10
10
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 ) )
13
13
end )
14
14
15
15
assert_receive response
@@ -20,115 +20,113 @@ defmodule ExDoc.CLITest do
20
20
{ [ html , epub ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin ] )
21
21
22
22
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
+ ] } }
30
31
31
32
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
+ ] } }
39
41
end
40
42
41
43
test "formatter option" do
42
44
{ [ epub , html ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin , "-f" , "epub" , "-f" , "html" ] )
43
45
44
46
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
+ ] } }
52
55
53
56
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
+ ] } }
61
65
end
62
66
63
67
test "version" do
64
68
{ _ , io } = run ( [ "--version" ] )
65
- assert io == "ExDoc v#{ ExDoc . version ( ) } \n "
69
+ assert io =~ "ExDoc v#{ ExDoc . version ( ) } \n "
66
70
67
71
{ _ , io } = run ( [ "--version" ] )
68
- assert io == "ExDoc v#{ ExDoc . version ( ) } \n "
72
+ assert io =~ "ExDoc v#{ ExDoc . version ( ) } \n "
69
73
end
70
74
71
75
describe "--warnings-as-errors" do
72
76
@ describetag :warnings
73
77
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
75
79
ExDoc.Utils . unset_warned ( )
76
80
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
- ] }
98
- end
81
+ Mix.Project . in_project ( :single , "test/fixtures/single" , fn _mod ->
82
+ source_beam = "_build/test/lib/single/ebin"
99
83
100
- test "exits with 1 when there is a warning" do
101
- ExDoc.Utils . set_warned ( )
84
+ fun = fn ->
85
+ run (
86
+ [ "Single" , "1.2.3" , source_beam , "--formatter=html" ] ,
87
+ & ExDoc . generate_docs / 3 ,
88
+ :stderr
89
+ )
90
+ end
102
91
103
- fun = fn ->
104
- run ( [ "ExDoc" , "1.2.3" , @ ebin , "--warnings-as-errors" ] )
105
- end
92
+ { [ _html ] , io } = fun . ( )
106
93
107
- io =
108
- capture_io ( :stderr , fn ->
109
- assert catch_exit ( fun . ( ) ) == { :shutdown , 1 }
110
- end )
94
+ assert io =~
95
+ ~s| documentation references function \" Single.bar/0\" but it is undefined or private|
111
96
112
- assert io =~
113
- "Doc generation failed due to warnings while using the --warnings-as-errors option\n "
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
+ end
102
+ end )
114
103
end
115
104
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 ( )
105
+ test "exits with 1 when there are warnings with --warnings-as-errors flag" do
106
+ ExDoc.Utils . unset_warned ( )
120
107
121
- fun = fn ->
122
- run ( [ "ExDoc" , "1.2.3" , @ ebin , "--warnings-as-errors" ] )
123
- end
108
+ Mix.Project . in_project ( :single , "test/fixtures/single" , fn _mod ->
109
+ source_beam = "_build/test/lib/single/ebin"
124
110
125
- io =
126
- capture_io ( :stderr , fn ->
127
- assert catch_exit ( fun . ( ) ) == { :shutdown , 1 }
128
- end )
111
+ fun = fn ->
112
+ run (
113
+ [ "Single" , "1.2.3" , source_beam , "--formatter=html" , "--warnings-as-errors" ] ,
114
+ & ExDoc . generate_docs / 3 ,
115
+ :stderr
116
+ )
117
+ end
129
118
130
- assert io =~
131
- "Doc generation failed due to warnings while using the --warnings-as-errors option\n "
119
+ # fun.()
120
+
121
+ io =
122
+ capture_io ( :stderr , fn ->
123
+ assert catch_exit ( fun . ( ) ) == { :shutdown , 1 }
124
+ end )
125
+
126
+ assert io =~
127
+ "Documents have been generated, but generation for html format failed due to warnings " <>
128
+ "while using the --warnings-as-errors option."
129
+ end )
132
130
end
133
131
end
134
132
@@ -156,7 +154,7 @@ defmodule ExDoc.CLITest do
156
154
--canonical http://example.com/project
157
155
)
158
156
159
- { [ { project , version , opts } ] , _io } = run ( args )
157
+ { [ { :ok , { project , version , opts } } ] , _io } = run ( args )
160
158
assert project == "ExDoc"
161
159
assert version == "1.2.3"
162
160
@@ -187,7 +185,7 @@ defmodule ExDoc.CLITest do
187
185
test "loading" do
188
186
File . write! ( "test.exs" , ~s( [extras: ["README.md"], formatters: ["html"]]) )
189
187
190
- { [ { project , version , opts } ] , _io } =
188
+ { [ { :ok , { project , version , opts } } ] , _io } =
191
189
run ( [ "ExDoc" , "--extra-section" , "Guides" , "1.2.3" , @ ebin , "-c" , "test.exs" ] )
192
190
193
191
assert project == "ExDoc"
@@ -208,7 +206,7 @@ defmodule ExDoc.CLITest do
208
206
test "switches take precedence over config" do
209
207
File . write! ( "test.exs" , ~s( [logo: "config_logo.png", formatters: ["html"]]) )
210
208
211
- { [ { project , version , opts } ] , _io } =
209
+ { [ { :ok , { project , version , opts } } ] , _io } =
212
210
run ( [
213
211
"ExDoc" ,
214
212
"--logo" ,
@@ -254,7 +252,8 @@ defmodule ExDoc.CLITest do
254
252
test "loading" do
255
253
File . write! ( "test.config" , ~s( {extras, [<<"README.md">>]}. {formatters, [<<"html">>]}.) )
256
254
257
- { [ { project , version , opts } ] , _io } = run ( [ "ExDoc" , "1.2.3" , @ ebin , "-c" , "test.config" ] )
255
+ { [ { :ok , { project , version , opts } } ] , _io } =
256
+ run ( [ "ExDoc" , "1.2.3" , @ ebin , "-c" , "test.config" ] )
258
257
259
258
assert project == "ExDoc"
260
259
assert version == "1.2.3"
0 commit comments