@@ -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,116 @@ 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
- ] }
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 )
98
106
end
99
107
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 ( )
102
110
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"
106
113
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
111
121
112
- assert io =~
113
- "Doc generation failed due to warnings while using the --warnings-as-errors option\n "
114
- end
122
+ # fun.()
115
123
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 )
120
128
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 )
132
133
end
133
134
end
134
135
@@ -156,7 +157,7 @@ defmodule ExDoc.CLITest do
156
157
--canonical http://example.com/project
157
158
)
158
159
159
- { [ { project , version , opts } ] , _io } = run ( args )
160
+ { [ { :ok , { project , version , opts } } ] , _io } = run ( args )
160
161
assert project == "ExDoc"
161
162
assert version == "1.2.3"
162
163
@@ -187,7 +188,7 @@ defmodule ExDoc.CLITest do
187
188
test "loading" do
188
189
File . write! ( "test.exs" , ~s( [extras: ["README.md"], formatters: ["html"]]) )
189
190
190
- { [ { project , version , opts } ] , _io } =
191
+ { [ { :ok , { project , version , opts } } ] , _io } =
191
192
run ( [ "ExDoc" , "--extra-section" , "Guides" , "1.2.3" , @ ebin , "-c" , "test.exs" ] )
192
193
193
194
assert project == "ExDoc"
@@ -208,7 +209,7 @@ defmodule ExDoc.CLITest do
208
209
test "switches take precedence over config" do
209
210
File . write! ( "test.exs" , ~s( [logo: "config_logo.png", formatters: ["html"]]) )
210
211
211
- { [ { project , version , opts } ] , _io } =
212
+ { [ { :ok , { project , version , opts } } ] , _io } =
212
213
run ( [
213
214
"ExDoc" ,
214
215
"--logo" ,
@@ -254,7 +255,8 @@ defmodule ExDoc.CLITest do
254
255
test "loading" do
255
256
File . write! ( "test.config" , ~s( {extras, [<<"README.md">>]}. {formatters, [<<"html">>]}.) )
256
257
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" ] )
258
260
259
261
assert project == "ExDoc"
260
262
assert version == "1.2.3"
0 commit comments