@@ -2889,3 +2889,78 @@ $DIR/short-error-format.rs:8:7: error[E0599]: no method named `salut` found for
28892889 . anonymized_line_numbers ( true ) ;
28902890 assert_data_eq ! ( renderer. render( input) , expected) ;
28912891}
2892+
2893+ #[ test]
2894+ fn rustdoc_ui_diagnostic_width ( ) {
2895+ // tests/rustdoc-ui/diagnostic-width.rs
2896+
2897+ let source_0 = r#"//@ compile-flags: --diagnostic-width=10
2898+ #![deny(rustdoc::bare_urls)]
2899+
2900+ /// This is a long line that contains a http://link.com
2901+ pub struct Foo; //~^ ERROR
2902+ "# ;
2903+ let source_1 = r#"/// This is a long line that contains a http://link.com
2904+ "# ;
2905+
2906+ let input = Level :: ERROR
2907+ . header ( "this URL is not a hyperlink" )
2908+ . group (
2909+ Group :: new ( )
2910+ . element (
2911+ Snippet :: source ( source_0)
2912+ . origin ( "$DIR/diagnostic-width.rs" )
2913+ . fold ( true )
2914+ . annotation ( AnnotationKind :: Primary . span ( 111 ..126 ) ) ,
2915+ )
2916+ . element (
2917+ Level :: NOTE
2918+ . title ( "bare URLs are not automatically turned into clickable links" ) ,
2919+ ) ,
2920+ )
2921+ . group (
2922+ Group :: new ( )
2923+ . element ( Level :: NOTE . title ( "the lint level is defined here" ) )
2924+ . element (
2925+ Snippet :: source ( source_0)
2926+ . origin ( "$DIR/diagnostic-width.rs" )
2927+ . fold ( true )
2928+ . annotation ( AnnotationKind :: Primary . span ( 49 ..67 ) ) ,
2929+ ) ,
2930+ )
2931+ . group (
2932+ Group :: new ( )
2933+ . element ( Level :: HELP . title ( "use an automatic link instead" ) )
2934+ . element (
2935+ Snippet :: source ( source_1)
2936+ . origin ( "$DIR/diagnostic-width.rs" )
2937+ . line_start ( 4 )
2938+ . fold ( true )
2939+ . patch ( Patch :: new ( 40 ..40 , "<" ) )
2940+ . patch ( Patch :: new ( 55 ..55 , ">" ) ) ,
2941+ ) ,
2942+ ) ;
2943+
2944+ let expected = str![ [ r#"
2945+ error: this URL is not a hyperlink
2946+ --> $DIR/diagnostic-width.rs:4:41
2947+ |
2948+ LL | ... a http://link.com
2949+ | ^^^^^^^^^^^^^^^
2950+ |
2951+ = note: bare URLs are not automatically turned into clickable links
2952+ note: the lint level is defined here
2953+ --> $DIR/diagnostic-width.rs:2:9
2954+ |
2955+ LL | ...ny(ru...are_urls)]
2956+ | ^^...^^^^^^^^
2957+ help: use an automatic link instead
2958+ |
2959+ LL | /// This is a long line that contains a <http://link.com>
2960+ | + +
2961+ "# ] ] ;
2962+ let renderer = Renderer :: plain ( )
2963+ . anonymized_line_numbers ( true )
2964+ . term_width ( 10 ) ;
2965+ assert_data_eq ! ( renderer. render( input) , expected) ;
2966+ }
0 commit comments