@@ -80,11 +80,12 @@ mod cli {
8080
8181 /// Parse lychee's json output to [`Value`].
8282 /// Additionally remove the non-deterministic duration to simplify subsequent assertions
83- fn stdout_to_json ( stdout : & [ u8 ] ) -> Result < Value > {
84- let mut output_json = serde_json:: from_slice :: < Value > ( stdout) ?;
83+ fn stdout_to_json ( stdout : & [ u8 ] ) -> Value {
84+ let mut output_json =
85+ serde_json:: from_slice :: < Value > ( stdout) . expect ( "stdout is not valid JSON" ) ;
8586 remove_nondeterministic_duration ( & mut output_json[ "success_map" ] ) ;
86- remove_nondeterministic_duration ( & mut output_json[ "redirect_map " ] ) ;
87- return Ok ( output_json) ;
87+ remove_nondeterministic_duration ( & mut output_json[ "excluded_map " ] ) ;
88+ return output_json;
8889
8990 fn remove_nondeterministic_duration ( value : & mut Value ) {
9091 let map = value. as_object_mut ( ) . expect ( "Expected object" ) ;
@@ -197,7 +198,7 @@ mod cli {
197198 . assert ( )
198199 . success ( ) ;
199200 let output = cmd. output ( ) . unwrap ( ) ;
200- let output_json = stdout_to_json ( & output. stdout ) ? ;
201+ let output_json = stdout_to_json ( & output. stdout ) ;
201202
202203 // Check that the output is valid JSON
203204 assert ! ( output_json. is_object( ) ) ;
@@ -257,7 +258,7 @@ mod cli {
257258 let output = cmd. output ( ) ?;
258259
259260 // Check that the output is valid JSON
260- stdout_to_json ( & output. stdout ) ? ;
261+ stdout_to_json ( & output. stdout ) ;
261262 Ok ( ( ) )
262263 }
263264
@@ -276,7 +277,7 @@ mod cli {
276277 let output = cmd. output ( ) ?;
277278
278279 // Parse site error status from the error_map
279- let output_json = stdout_to_json ( & output. stdout ) ? ;
280+ let output_json = stdout_to_json ( & output. stdout ) ;
280281 let site_error_status =
281282 & output_json[ "error_map" ] [ & test_path. to_str ( ) . unwrap ( ) ] [ 0 ] [ "status" ] ;
282283
@@ -901,24 +902,20 @@ mod cli {
901902
902903 /// Test excludes
903904 #[ test]
904- fn test_exclude_wildcard ( ) -> Result < ( ) > {
905+ fn test_exclude_wildcard ( ) {
905906 let test_path = fixtures_path ! ( ) . join ( "TEST.md" ) ;
906-
907907 cargo_bin_cmd ! ( )
908908 . arg ( test_path)
909909 . arg ( "--exclude" )
910910 . arg ( ".*" )
911911 . assert ( )
912912 . success ( )
913913 . stdout ( contains ( "12 Excluded" ) ) ;
914-
915- Ok ( ( ) )
916914 }
917915
918916 #[ test]
919- fn test_exclude_multiple_urls ( ) -> Result < ( ) > {
917+ fn test_exclude_multiple_urls ( ) {
920918 let test_path = fixtures_path ! ( ) . join ( "TEST.md" ) ;
921-
922919 cargo_bin_cmd ! ( )
923920 . arg ( test_path)
924921 . arg ( "--exclude" )
@@ -928,8 +925,6 @@ mod cli {
928925 . assert ( )
929926 . success ( )
930927 . stdout ( contains ( "4 Excluded" ) ) ;
931-
932- Ok ( ( ) )
933928 }
934929
935930 #[ tokio:: test]
@@ -1913,7 +1908,7 @@ The config file should contain every possible key for documentation purposes."
19131908 }
19141909
19151910 #[ test]
1916- fn test_erroneous_remap_with_redirect_real_world ( ) {
1911+ fn test_erroneous_remap_with_redirect ( ) {
19171912 cargo_bin_cmd ! ( )
19181913 . arg ( "-vv" )
19191914 . arg ( "--remap" )
@@ -1948,6 +1943,42 @@ The config file should contain every possible key for documentation purposes."
19481943 . stdout ( contains ( "The given URI is invalid, check URI syntax: https://example.com/" ) ) ;
19491944 }
19501945
1946+ #[ test]
1947+ fn test_remap_to_excluded ( ) {
1948+ let stdout = cargo_bin_cmd ! ( )
1949+ . arg ( "--remap=aaa bbb" )
1950+ . arg ( "--exclude=bbb" )
1951+ . arg ( "--format=json" )
1952+ . arg ( "-" )
1953+ . write_stdin ( "https://aaa.com" )
1954+ . assert ( )
1955+ . success ( )
1956+ . get_output ( )
1957+ . stdout
1958+ . clone ( ) ;
1959+
1960+ let json = stdout_to_json ( & stdout) ;
1961+ assert_eq ! ( json[ "remaps" ] , 1 ) ;
1962+ assert_eq ! ( json[ "excludes" ] , 1 ) ;
1963+ assert_eq ! (
1964+ json[ "excluded_map" ] ,
1965+ json!( {
1966+ "stdin" : [
1967+ {
1968+ "url" : "https://bbb.com/" ,
1969+ "status" : {
1970+ "text" : "Excluded" ,
1971+ "details" : "This is due to your 'exclude' values | Remapped: https://aaa.com/ --> https://bbb.com/"
1972+ } ,
1973+ "span" : {
1974+ "line" : 1 ,
1975+ "column" : 1
1976+ } ,
1977+ }
1978+ ] } )
1979+ ) ;
1980+ }
1981+
19511982 #[ test]
19521983 fn test_excluded_paths_regex ( ) {
19531984 let test_path = fixtures_path ! ( ) . join ( "exclude-path" ) ;
@@ -2574,7 +2605,8 @@ The config file should contain every possible key for documentation purposes."
25742605 assert_eq!( json[ "total" ] , 1 ) ;
25752606 assert_eq!( json[ "redirects" ] , 1 ) ; // there was one redirect
25762607 assert_eq!( json[ "successful" ] , 1 ) ; // which resolved to a success
2577- assert_eq!( json[ "redirect_map" ] , json!( { } ) ) ;
2608+ assert_eq!( json[ "redirect_map" ] , json!( { } ) ) ; // suppressed in non-verbose mode
2609+ assert_eq!( json[ "success_map" ] , json!( { } ) ) ; // suppressed in non-verbose mode
25782610 } )
25792611 . await ;
25802612
@@ -2587,6 +2619,17 @@ The config file should contain every possible key for documentation purposes."
25872619 assert_eq!(
25882620 json[ "redirect_map" ] ,
25892621 json!( {
2622+ "stdin" : [ {
2623+ "origin" : redirect_url,
2624+ "redirects" : [ {
2625+ "code" : 308 ,
2626+ "url" : ok_url,
2627+ } ]
2628+ } ] } )
2629+ ) ;
2630+ assert_eq!(
2631+ json[ "success_map" ] ,
2632+ json!( {
25902633 "stdin" : [ {
25912634 "span" : {
25922635 "column" : 1 ,
@@ -2630,7 +2673,7 @@ The config file should contain every possible key for documentation purposes."
26302673
26312674 let stderr = str:: from_utf8 ( & output. stderr ) . unwrap ( ) . to_string ( ) ;
26322675
2633- ( stdout_to_json ( & output. stdout ) . unwrap ( ) , stderr)
2676+ ( stdout_to_json ( & output. stdout ) , stderr)
26342677 }
26352678 }
26362679
0 commit comments