@@ -2,6 +2,8 @@ defmodule ExDoc.Formatter.HTMLTest do
2
2
use ExUnit.Case , async: true
3
3
4
4
import ExUnit.CaptureIO
5
+ import TestHelper , only: [ isolated_warning_counter: 1 ]
6
+
5
7
alias ExDoc.Formatter.HTML
6
8
7
9
@ moduletag :tmp_dir
@@ -124,7 +126,9 @@ defmodule ExDoc.Formatter.HTMLTest do
124
126
generate_docs ( doc_config ( context , main: "Randomerror" ) )
125
127
end )
126
128
127
- assert output =~ "warning: index.html redirects to Randomerror.html, which does not exist\n "
129
+ assert output =~
130
+ ~R" warning: .+index.html redirects to Randomerror.html, which does not exist\n"
131
+
128
132
assert File . regular? ( tmp_dir <> "/html/index.html" )
129
133
assert File . regular? ( tmp_dir <> "/html/RandomError.html" )
130
134
end
@@ -141,6 +145,63 @@ defmodule ExDoc.Formatter.HTMLTest do
141
145
assert output =~ ~r" Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
142
146
end
143
147
148
+ describe "warning counter" do
149
+ @ describetag :warning_counter
150
+
151
+ test "4 warnings are counted when using warnings_as_errors: true" , context do
152
+ isolated_warning_counter do
153
+ output =
154
+ capture_io ( :stderr , fn ->
155
+ generate_docs (
156
+ doc_config ( context ,
157
+ skip_undefined_reference_warnings_on: [ ] ,
158
+ warnings_as_errors: true
159
+ )
160
+ )
161
+ end )
162
+
163
+ assert output =~ ~r" Warnings.bar/0.*\n test/fixtures/warnings.ex:2: Warnings"
164
+ assert output =~ ~r" Warnings.bar/0.*\n test/fixtures/warnings.ex:18: Warnings.foo/0"
165
+
166
+ assert output =~
167
+ ~r" Warnings.bar/0.*\n test/fixtures/warnings.ex:13: c:Warnings.handle_foo/0"
168
+
169
+ assert output =~ ~r" Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
170
+
171
+ assert ExDoc.WarningCounter . count ( ) == 4
172
+ end
173
+ end
174
+
175
+ test "warnings are still counted even with warnings_as_errors: false" , context do
176
+ isolated_warning_counter do
177
+ capture_io ( :stderr , fn ->
178
+ generate_docs (
179
+ doc_config ( context ,
180
+ skip_undefined_reference_warnings_on: [ ] ,
181
+ warnings_as_errors: false
182
+ )
183
+ )
184
+ end )
185
+
186
+ assert ExDoc.WarningCounter . count ( ) == 4
187
+ end
188
+ end
189
+
190
+ test "1 warning is counted when using warnings_as_errors: true" , context do
191
+ isolated_warning_counter do
192
+ output =
193
+ capture_io ( :stderr , fn ->
194
+ generate_docs ( doc_config ( context , main: "DoesNotExist" , warnings_as_errors: true ) )
195
+ end )
196
+
197
+ assert output =~
198
+ ~R" warning: .+index.html redirects to DoesNotExist.html, which does not exist\n"
199
+
200
+ assert ExDoc.WarningCounter . count ( ) == 1
201
+ end
202
+ end
203
+ end
204
+
144
205
test "generates headers for index.html and module pages" , % { tmp_dir: tmp_dir } = context do
145
206
generate_docs ( doc_config ( context , main: "RandomError" ) )
146
207
content_index = File . read! ( tmp_dir <> "/html/index.html" )
0 commit comments