@@ -179,10 +179,9 @@ impl Test {
179179
180180impl Test {
181181 /// Creates a new default test on disk.
182- pub fn create_default ( paths : & Paths , vcs : Option < & Vcs > , id : Id ) -> Result < Test , CreateError > {
182+ pub fn create_default ( paths : & Paths , id : Id ) -> Result < Test , CreateError > {
183183 Self :: create (
184184 paths,
185- vcs,
186185 id,
187186 DEFAULT_TEST_INPUT ,
188187 Some ( Reference :: Persistent ( Document :: new ( [ Pixmap :: decode_png (
@@ -195,7 +194,6 @@ impl Test {
195194 /// Creates a new test on disk.
196195 pub fn create (
197196 paths : & Paths ,
198- vcs : Option < & Vcs > ,
199197 id : Id ,
200198 source : & str ,
201199 reference : Option < Reference > ,
@@ -236,20 +234,16 @@ impl Test {
236234 this. create_reference_script ( paths, reference. as_str ( ) ) ?;
237235 }
238236 Some ( Reference :: Persistent ( reference) ) => {
239- this. create_reference_documents ( paths, & reference) ?;
237+ this. create_reference_documents ( paths, None , & reference) ?;
240238 }
241239 None => { }
242240 }
243241
244- if let Some ( vcs) = vcs {
245- this. ignore_temporary_directories ( paths, vcs) ?;
246- }
247-
248242 Ok ( this)
249243 }
250244
251245 /// Creates this test's temporary directories, if they don't exist yet.
252- pub fn create_temporary_directories ( & self , paths : & Paths ) -> io:: Result < ( ) > {
246+ pub fn create_temporary_directories ( & self , paths : & Paths , vcs : Option < & Vcs > ) -> io:: Result < ( ) > {
253247 self . delete_temporary_directories ( paths) ?;
254248
255249 if self . kind . is_ephemeral ( ) {
@@ -258,6 +252,11 @@ impl Test {
258252
259253 stdx:: fs:: create_dir ( paths. test_out_dir ( & self . id ) , true ) ?;
260254 stdx:: fs:: create_dir ( paths. test_diff_dir ( & self . id ) , true ) ?;
255+
256+ if let Some ( vcs) = vcs {
257+ self . ignore_temporary_directories ( paths, vcs) ?;
258+ }
259+
261260 Ok ( ( ) )
262261 }
263262
@@ -279,6 +278,7 @@ impl Test {
279278 pub fn create_reference_documents (
280279 & self ,
281280 paths : & Paths ,
281+ vcs : Option < & Vcs > ,
282282 reference : & Document ,
283283 ) -> Result < ( ) , SaveError > {
284284 // NOTE(tinger): if there are already more pages than we want to create,
@@ -289,6 +289,13 @@ impl Test {
289289 let ref_dir = paths. test_ref_dir ( & self . id ) ;
290290 stdx:: fs:: create_dir ( & ref_dir, true ) ?;
291291 reference. save ( & ref_dir) ?;
292+
293+ if self . kind ( ) . is_ephemeral ( ) {
294+ if let Some ( vcs) = vcs {
295+ self . ignore_reference_documents ( paths, vcs) ?;
296+ }
297+ }
298+
292299 Ok ( ( ) )
293300 }
294301
@@ -381,7 +388,7 @@ impl Test {
381388 reference : & Document ,
382389 ) -> Result < ( ) , SaveError > {
383390 self . delete_reference_script ( paths) ?;
384- self . create_reference_documents ( paths, reference) ?;
391+ self . create_reference_documents ( paths, vcs , reference) ?;
385392 if let Some ( vcs) = vcs {
386393 self . unignore_reference_documents ( paths, vcs) ?;
387394 }
@@ -422,23 +429,22 @@ impl Test {
422429 /// Loads the reference test script source of this test, if this test is
423430 /// ephemeral.
424431 pub fn load_reference_source ( & self , paths : & Paths ) -> io:: Result < Option < Source > > {
425- match self . kind {
426- Kind :: Ephemeral => {
427- let ref_script = paths. test_ref_script ( & self . id ) ;
428- Ok ( Some ( Source :: new (
429- FileId :: new (
430- None ,
431- VirtualPath :: new (
432- ref_script
433- . strip_prefix ( paths. project_root ( ) )
434- . unwrap_or ( & ref_script) ,
435- ) ,
436- ) ,
437- std:: fs:: read_to_string ( ref_script) ?,
438- ) ) )
439- }
440- _ => Ok ( None ) ,
432+ if !self . kind ( ) . is_ephemeral ( ) {
433+ return Ok ( None ) ;
441434 }
435+
436+ let ref_script = paths. test_ref_script ( & self . id ) ;
437+ Ok ( Some ( Source :: new (
438+ FileId :: new (
439+ None ,
440+ VirtualPath :: new (
441+ ref_script
442+ . strip_prefix ( paths. project_root ( ) )
443+ . unwrap_or ( & ref_script) ,
444+ ) ,
445+ ) ,
446+ std:: fs:: read_to_string ( ref_script) ?,
447+ ) ) )
442448 }
443449
444450 /// Loads the persistent reference pages of this test, if they exist.
@@ -501,16 +507,15 @@ mod tests {
501507 }
502508
503509 #[ test]
504- fn test_create_new ( ) {
510+ fn test_create ( ) {
505511 _dev:: fs:: TempEnv :: run (
506512 |root| root. setup_dir ( "tests" ) ,
507513 |root| {
508514 let paths = Paths :: new ( root, None ) ;
509- Test :: create ( & paths, None , id ( "compile-only" ) , "Hello World" , None ) . unwrap ( ) ;
515+ Test :: create ( & paths, id ( "compile-only" ) , "Hello World" , None ) . unwrap ( ) ;
510516
511517 Test :: create (
512518 & paths,
513- None ,
514519 id ( "ephemeral" ) ,
515520 "Hello World" ,
516521 Some ( Reference :: Ephemeral ( "Hello\n World" . into ( ) ) ) ,
@@ -519,18 +524,21 @@ mod tests {
519524
520525 Test :: create (
521526 & paths,
522- None ,
523527 id ( "persistent" ) ,
524528 "Hello World" ,
525529 Some ( Reference :: Persistent ( Document :: new ( vec ! [ ] ) ) ) ,
526530 )
527531 . unwrap ( ) ;
532+
533+ Test :: create_default ( & paths, id ( "default" ) ) . unwrap ( ) ;
528534 } ,
529535 |root| {
530536 root. expect_file_content ( "tests/compile-only/test.typ" , "Hello World" )
531537 . expect_file_content ( "tests/ephemeral/test.typ" , "Hello World" )
532538 . expect_file_content ( "tests/ephemeral/ref.typ" , "Hello\n World" )
533539 . expect_file_content ( "tests/persistent/test.typ" , "Hello World" )
540+ . expect_file_content ( "tests/default/test.typ" , DEFAULT_TEST_INPUT )
541+ . expect_file ( "tests/default/ref/1.png" )
534542 . expect_dir ( "tests/persistent/ref" )
535543 } ,
536544 ) ;
0 commit comments