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