@@ -384,6 +384,12 @@ fn render_compile(output: &mut String, cases: &[&ScenarioCase]) -> Result<()> {
384384 output. push_str ( "use anyhow::Result;\n " ) ;
385385 output. push_str ( "use assert_cmd::assert::OutputAssertExt;\n " ) ;
386386 output. push_str ( "use assert_fs::fixture::{FileWriteStr, PathChild};\n " ) ;
387+ if cases
388+ . iter ( )
389+ . any ( |case| case. scenario . root . requires . len ( ) > 1 )
390+ {
391+ output. push_str ( "use indoc::indoc;\n " ) ;
392+ }
387393 output. push_str ( "use predicates::prelude::predicate;\n \n " ) ;
388394 output. push_str ( "use uv_static::EnvVars;\n " ) ;
389395 output. push_str ( "use uv_test::packse::PackseServer;\n " ) ;
@@ -451,7 +457,21 @@ fn render_compile_case(output: &mut String, case: &ScenarioCase) -> Result<()> {
451457 output. push ( '\n' ) ;
452458 output. push_str ( " let requirements_in = context.temp_dir.child(\" requirements.in\" );\n " ) ;
453459 let requirements = compile_requirements ( & case. scenario . root . requires ) ;
454- writeln ! ( output, " requirements_in.write_str({requirements:?})?;" ) . unwrap ( ) ;
460+ if case. scenario . root . requires . len ( ) > 1 {
461+ let requirements = requirements
462+ . lines ( )
463+ . map ( |line| {
464+ let quoted = format ! ( "{line:?}" ) ;
465+ format ! ( " {}" , & quoted[ 1 ..quoted. len( ) - 1 ] )
466+ } )
467+ . join ( "\n " ) ;
468+ writeln ! (
469+ output,
470+ " requirements_in.write_str(indoc! {{\" \n {requirements}\n \" }})?;"
471+ ) ?;
472+ } else {
473+ writeln ! ( output, " requirements_in.write_str({requirements:?})?;" ) ?;
474+ }
455475 output. push ( '\n' ) ;
456476 render_expected_explanation ( output, & case. scenario , " // " ) ;
457477 output. push_str (
@@ -929,6 +949,8 @@ fn requirement_specifiers(requirement: &Requirement) -> Option<&uv_pep440::Versi
929949
930950#[ cfg( test) ]
931951mod tests {
952+ use indoc:: { formatdoc, indoc} ;
953+
932954 use super :: {
933955 TemplateKind , check_generated_file, compile_requirements, load_scenarios,
934956 load_scenarios_from, module_name, render, scenarios_for_template,
@@ -941,7 +963,13 @@ mod tests {
941963 "b>=2.0.0" . parse ( ) . expect ( "valid requirement" ) ,
942964 ] ;
943965
944- assert_eq ! ( compile_requirements( & requirements) , "a==1.0.0\n b>=2.0.0" ) ;
966+ assert_eq ! (
967+ compile_requirements( & requirements) ,
968+ indoc! { "
969+ a==1.0.0
970+ b>=2.0.0"
971+ }
972+ ) ;
945973 }
946974
947975 #[ test]
@@ -982,10 +1010,12 @@ mod tests {
9821010
9831011 assert ! ( universal_cases. peek( ) . is_some( ) ) ;
9841012 for case in universal_cases {
985- assert ! ( output. contains( & format!(
986- "#[cfg(feature = \" test-universal\" )]\n #[test]\n fn {}()" ,
1013+ assert ! ( output. contains( & formatdoc! { r#"
1014+ #[cfg(feature = "test-universal")]
1015+ #[test]
1016+ fn {}()"# ,
9871017 module_name( & case. scenario. name)
988- ) ) ) ;
1018+ } ) ) ;
9891019 }
9901020 }
9911021
@@ -1070,13 +1100,26 @@ kind = "compile"
10701100 let path = temporary_directory. path ( ) . join ( "scenario.rs" ) ;
10711101 fs_err:: write (
10721102 & path,
1073- "/// Literal @\" accepted\" remains significant.\n fn scenario() {\n uv_snapshot!(filters, cmd, @\" \n accepted output\n \" );\n }\n " ,
1103+ indoc ! { r#"
1104+ /// Literal @"accepted" remains significant.
1105+ fn scenario() {
1106+ uv_snapshot!(filters, cmd, @"
1107+ accepted output
1108+ ");
1109+ }
1110+ "# } ,
10741111 )
10751112 . expect ( "temporary file should be written" ) ;
10761113
10771114 check_generated_file (
10781115 & path,
1079- "/// Literal @\" accepted\" remains significant.\n fn scenario() {\n uv_snapshot!(filters, cmd, @r#\" <snapshot>\n \" #);\n }\n " ,
1116+ indoc ! { r##"
1117+ /// Literal @"accepted" remains significant.
1118+ fn scenario() {
1119+ uv_snapshot!(filters, cmd, @r#"<snapshot>
1120+ "#);
1121+ }
1122+ "## } ,
10801123 )
10811124 . expect ( "accepted snapshot should not make generated file stale" ) ;
10821125 }
@@ -1088,13 +1131,26 @@ kind = "compile"
10881131 let path = temporary_directory. path ( ) . join ( "scenario.rs" ) ;
10891132 fs_err:: write (
10901133 & path,
1091- "/// Literal @\" current\" remains significant.\n fn scenario() {\n uv_snapshot!(filters, cmd, @\" \n accepted output\n \" );\n }\n " ,
1134+ indoc ! { r#"
1135+ /// Literal @"current" remains significant.
1136+ fn scenario() {
1137+ uv_snapshot!(filters, cmd, @"
1138+ accepted output
1139+ ");
1140+ }
1141+ "# } ,
10921142 )
10931143 . expect ( "temporary file should be written" ) ;
10941144
10951145 check_generated_file (
10961146 & path,
1097- "/// Literal @\" generated\" remains significant.\n fn scenario() {\n uv_snapshot!(filters, cmd, @r#\" <snapshot>\n \" #);\n }\n " ,
1147+ indoc ! { r##"
1148+ /// Literal @"generated" remains significant.
1149+ fn scenario() {
1150+ uv_snapshot!(filters, cmd, @r#"<snapshot>
1151+ "#);
1152+ }
1153+ "## } ,
10981154 )
10991155 . expect_err ( "documentation changes should make generated output stale" ) ;
11001156 }
0 commit comments