@@ -350,21 +350,59 @@ defmodule ExDoc.Language.ErlangTest do
350
350
describe "autolink_doc/2 for markdown warnings" do
351
351
@ describetag warnings: :send
352
352
353
+ test "bad function in module" , c do
354
+ assert warn (
355
+ fn ->
356
+ assert autolink_doc ( "\n `erlang_bar:bad/0`" , c ) ==
357
+ ~s| <code class="inline">erlang_bar:bad/0</code>|
358
+ end ,
359
+ line: 2
360
+ ) =~
361
+ ~s| documentation references function "erlang_bar:bad/0" but it is undefined or private|
362
+ end
363
+
364
+ test "bad type in module" , c do
365
+ assert warn (
366
+ fn ->
367
+ assert autolink_doc ( "\n `t:erlang_bar:bad/0`" , c ) ==
368
+ ~s| <code class="inline">t:erlang_bar:bad/0</code>|
369
+ end ,
370
+ line: 2
371
+ ) =~
372
+ ~s| documentation references type "t:erlang_bar:bad/0" but it is undefined or private|
373
+ end
374
+
375
+ test "bad callback in module" , c do
376
+ assert warn (
377
+ fn ->
378
+ assert autolink_doc ( "\n `c:erlang_bar:bad/0`" , c ) ==
379
+ ~s| <code class="inline">c:erlang_bar:bad/0</code>|
380
+ end ,
381
+ line: 2
382
+ ) =~ ~s| documentation references callback "c:erlang_bar:bad/0" but it is undefined|
383
+ end
384
+
353
385
test "bad function in module ref" , c do
354
- assert warn ( fn ->
355
- assert autolink_doc ( "[Bad](`bad/0`)" , c ) == ~s| Bad|
356
- end ) =~ ~s| documentation references function "bad/0" but it is undefined or private|
386
+ assert warn (
387
+ fn ->
388
+ assert autolink_doc ( "[Bad](`bad/0`)" , c ) == ~s| Bad|
389
+ end ,
390
+ line: nil
391
+ ) =~ ~s| documentation references function "bad/0" but it is undefined or private|
357
392
end
358
393
359
394
test "linking to local extra works does not work" , c do
360
- assert warn ( fn ->
361
- assert autolink_doc ( "[extra](`e:extra.md`)" , c ) ==
362
- ~s| extra|
363
- end ) =~ ~r/ documentation references "e:extra.md" but it is invalid/
395
+ assert warn (
396
+ fn ->
397
+ assert autolink_doc ( "[extra](`e:extra.md`)" , c ) ==
398
+ ~s| extra|
399
+ end ,
400
+ line: nil
401
+ ) =~ ~r/ documentation references "e:extra.md" but it is invalid/
364
402
end
365
403
end
366
404
367
- describe "autolink_edoc /2 for extra" do
405
+ describe "autolink_doc /2 for extra" do
368
406
test "function" , c do
369
407
assert autolink_extra ( "`erlang_foo:foo/0`" , c ) ==
370
408
~s| <a href="erlang_foo.html#foo/0"><code class="inline">erlang_foo:foo/0</code></a>|
@@ -410,9 +448,16 @@ defmodule ExDoc.Language.ErlangTest do
410
448
~s| <code class="inline">...a/0</code>|
411
449
end
412
450
413
- test "bad type" , c do
414
- assert autolink_extra ( "`t:bad:bad/0`" , c ) ==
415
- ~s| <code class="inline">t:bad:bad/0</code>|
451
+ @ tag warnings: :send
452
+ test "bad type ref" , c do
453
+ assert warn (
454
+ fn ->
455
+ assert autolink_extra ( "[t](`t:bad:bad/0`)" , c ) ==
456
+ ~s| t|
457
+ end ,
458
+ file: "extra.md" ,
459
+ line: nil
460
+ ) =~ ~s| documentation references type "t:bad:bad/0" but it is undefined or private|
416
461
end
417
462
418
463
test "bad module" , c do
@@ -422,10 +467,14 @@ defmodule ExDoc.Language.ErlangTest do
422
467
423
468
@ tag warnings: :send
424
469
test "bad module using m:" , c do
425
- assert warn ( fn ->
426
- assert autolink_extra ( "`m:does_not_exist`" , c ) ==
427
- ~s| <code class="inline">m:does_not_exist</code>|
428
- end ) =~ ~r| documentation references module \" does_not_exist\" but it is undefined|
470
+ assert warn (
471
+ fn ->
472
+ assert autolink_extra ( "`m:does_not_exist`" , c ) ==
473
+ ~s| <code class="inline">m:does_not_exist</code>|
474
+ end ,
475
+ file: "extra.md" ,
476
+ line: 1
477
+ ) =~ ~r| documentation references module \" does_not_exist\" but it is undefined|
429
478
end
430
479
431
480
test "extras" do
@@ -618,7 +667,7 @@ defmodule ExDoc.Language.ErlangTest do
618
667
[ { :p , _ , [ ast ] , _ } ] = ExDoc.Markdown . to_ast ( text , [ ] )
619
668
620
669
opts = c |> Map . take ( [ :warnings ] ) |> Enum . to_list ( )
621
- do_autolink_doc ( ast , opts )
670
+ do_autolink_doc ( ast , [ file: "extra.md" ] ++ opts )
622
671
end
623
672
624
673
defp autolink_doc ( text , c , opts \\ [ ] ) do
@@ -637,6 +686,7 @@ defmodule ExDoc.Language.ErlangTest do
637
686
ast ,
638
687
[
639
688
current_module: :erlang_foo ,
689
+ file: "erlang_foo.erl" ,
640
690
module_id: "erlang_foo" ,
641
691
deps: [ foolib: "https://foolib.com" ]
642
692
] ++
@@ -668,9 +718,18 @@ defmodule ExDoc.Language.ErlangTest do
668
718
|> ExDoc.DocAST . to_string ( )
669
719
end
670
720
671
- defp warn ( fun ) when is_function ( fun , 0 ) do
721
+ defp warn ( fun , md \\ [ ] ) when is_function ( fun , 0 ) do
672
722
fun . ( )
673
- assert_received { :warn , message , _metadata }
723
+ assert_received { :warn , message , metadata }
724
+
725
+ if Keyword . has_key? ( md , :line ) do
726
+ assert md [ :line ] == metadata [ :line ]
727
+ end
728
+
729
+ if Keyword . has_key? ( md , :file ) do
730
+ assert md [ :file ] == metadata [ :file ]
731
+ end
732
+
674
733
message
675
734
end
676
735
0 commit comments