@@ -17,6 +17,8 @@ lazy_static::lazy_static! {
1717}
1818
1919/// Note: Used by tmc-server. Prepares a submission for further processing.
20+ /// The clone path is assumed to be a directory with the exercise name as the directory name,
21+ /// and the course name as its parent, ex. "anything/some_course/some_exercise"
2022pub fn prepare_submission (
2123 zip_path : & Path ,
2224 target_path : & Path ,
@@ -243,10 +245,27 @@ pub fn prepare_submission(
243245
244246 // make archive
245247 log:: debug!( "creating submission archive" ) ;
246- let prefix = toplevel_dir_name
247- . as_ref ( )
248- . map ( Path :: new)
249- . unwrap_or_else ( || Path :: new ( "" ) ) ;
248+
249+ let exercise_name = clone_path. file_name ( ) ;
250+ let course_name = clone_path. parent ( ) . and_then ( Path :: file_name) ;
251+ let prefix = match ( toplevel_dir_name, course_name, exercise_name) {
252+ ( Some ( toplevel_dir_name) , Some ( course_name) , Some ( exercise_name) ) => {
253+ Path :: new ( & toplevel_dir_name)
254+ . join ( course_name)
255+ . join ( exercise_name)
256+ }
257+ ( None , Some ( course_name) , Some ( exercise_name) ) => {
258+ Path :: new ( course_name) . join ( exercise_name)
259+ }
260+ _ => {
261+ log:: warn!(
262+ "was not able to find exercise and/or course name from clone path {}" ,
263+ clone_path. display( )
264+ ) ;
265+ PathBuf :: from ( "" )
266+ }
267+ } ;
268+
250269 let archive_file = file_util:: create_file ( target_path) ?;
251270 match output_format {
252271 OutputFormat :: Tar => {
@@ -362,13 +381,13 @@ mod test {
362381 use tempfile:: TempDir ;
363382 use walkdir:: WalkDir ;
364383
365- const MAVEN_CLONE : & str = "tests/data/MavenExercise" ;
384+ const MAVEN_CLONE : & str = "tests/data/some_course/ MavenExercise" ;
366385 const MAVEN_ZIP : & str = "tests/data/MavenExercise.zip" ;
367386
368- const MAKE_CLONE : & str = "tests/data/MakeExercise" ;
387+ const MAKE_CLONE : & str = "tests/data/some_course/ MakeExercise" ;
369388 const MAKE_ZIP : & str = "tests/data/MakeExercise.zip" ;
370389
371- const PYTHON_CLONE : & str = "tests/data/PythonExercise" ;
390+ const PYTHON_CLONE : & str = "tests/data/some_course/ PythonExercise" ;
372391 const PYTHON_ZIP : & str = "tests/data/PythonExercise.zip" ;
373392
374393 fn init ( ) {
@@ -417,10 +436,16 @@ mod test {
417436 init ( ) ;
418437 let ( _temp, output) = generic_submission ( MAVEN_CLONE , MAVEN_ZIP ) ;
419438 // expected files
420- assert ! ( output. join( "src/main/java/SimpleStuff.java" ) . exists( ) ) ;
421- assert ! ( output. join( "src/test/java/SimpleTest.java" ) . exists( ) ) ;
422- assert ! ( output. join( "src/test/java/SimpleHiddenTest.java" ) . exists( ) ) ;
423- assert ! ( output. join( "pom.xml" ) . exists( ) ) ;
439+ assert ! ( output
440+ . join( "some_course/MavenExercise/src/main/java/SimpleStuff.java" )
441+ . exists( ) ) ;
442+ assert ! ( output
443+ . join( "some_course/MavenExercise/src/test/java/SimpleTest.java" )
444+ . exists( ) ) ;
445+ assert ! ( output
446+ . join( "some_course/MavenExercise/src/test/java/SimpleHiddenTest.java" )
447+ . exists( ) ) ;
448+ assert ! ( output. join( "some_course/MavenExercise/pom.xml" ) . exists( ) ) ;
424449 }
425450
426451 #[ test]
@@ -429,8 +454,10 @@ mod test {
429454 let ( _temp, output) = generic_submission ( MAVEN_CLONE , MAVEN_ZIP ) ;
430455
431456 // files that should not be included
432- assert ! ( !output. join( "__MACOSX" ) . exists( ) ) ;
433- assert ! ( !output. join( "src/test/java/MadeUpTest.java" ) . exists( ) ) ;
457+ assert ! ( !output. join( "some_course/MavenExercise/__MACOSX" ) . exists( ) ) ;
458+ assert ! ( !output
459+ . join( "some_course/MavenExercise/src/test/java/MadeUpTest.java" )
460+ . exists( ) ) ;
434461 }
435462
436463 #[ test]
@@ -449,8 +476,10 @@ mod test {
449476 let contents = String :: from_utf8 ( writer) . unwrap ( ) ;
450477 assert ! ( contents. contains( "MODIFIED" ) ) ;
451478 // the text should not be in the package
452- let test_file =
453- fs:: read_to_string ( dbg ! ( output. join( "src/test/java/SimpleTest.java" ) ) ) . unwrap ( ) ;
479+ let test_file = fs:: read_to_string ( dbg ! (
480+ output. join( "some_course/MavenExercise/src/test/java/SimpleTest.java" )
481+ ) )
482+ . unwrap ( ) ;
454483 assert ! ( !test_file. contains( "MODIFIED" ) ) ;
455484 }
456485
@@ -459,7 +488,7 @@ mod test {
459488 init ( ) ;
460489 let ( _temp, output) = generic_submission ( MAVEN_CLONE , MAVEN_ZIP ) ;
461490
462- let param_file = output. join ( ".tmcparams" ) ;
491+ let param_file = output. join ( "some_course/MavenExercise/ .tmcparams" ) ;
463492 assert ! ( param_file. exists( ) ) ;
464493 let conts = fs:: read_to_string ( param_file) . unwrap ( ) ;
465494 log:: debug!( "tmcparams {}" , conts) ;
@@ -497,9 +526,11 @@ mod test {
497526 log:: debug!( "{}" , entry. unwrap( ) . path( ) . display( ) ) ;
498527 }
499528 assert ! ( output
500- . join( "toplevel/src/test/java/SimpleHiddenTest.java" )
529+ . join( "toplevel/some_course/MavenExercise/src/test/java/SimpleHiddenTest.java" )
530+ . exists( ) ) ;
531+ assert ! ( output
532+ . join( "toplevel/some_course/MavenExercise/pom.xml" )
501533 . exists( ) ) ;
502- assert ! ( output. join( "toplevel/pom.xml" ) . exists( ) ) ;
503534 }
504535
505536 #[ test]
@@ -530,8 +561,10 @@ mod test {
530561 for entry in WalkDir :: new ( temp. path ( ) ) {
531562 log:: debug!( "{}" , entry. unwrap( ) . path( ) . display( ) ) ;
532563 }
533- assert ! ( output. join( "src/test/java/SimpleHiddenTest.java" ) . exists( ) ) ;
534- assert ! ( output. join( "pom.xml" ) . exists( ) ) ;
564+ assert ! ( output
565+ . join( "some_course/MavenExercise/src/test/java/SimpleHiddenTest.java" )
566+ . exists( ) ) ;
567+ assert ! ( output. join( "some_course/MavenExercise/pom.xml" ) . exists( ) ) ;
535568 }
536569
537570 #[ test]
@@ -557,7 +590,7 @@ mod test {
557590 let output = file_util:: open_file ( output) . unwrap ( ) ;
558591 let mut archive = zip:: ZipArchive :: new ( output) . unwrap ( ) ;
559592 archive
560- . by_name ( "src/test/java/SimpleHiddenTest.java" )
593+ . by_name ( "some_course/MavenExercise/ src/test/java/SimpleHiddenTest.java" )
561594 . unwrap ( ) ;
562595 }
563596
@@ -584,9 +617,11 @@ mod test {
584617 let output = file_util:: open_file ( output) . unwrap ( ) ;
585618 let mut archive = zip:: ZipArchive :: new ( output) . unwrap ( ) ;
586619 archive
587- . by_name ( "toplevel/src/test/java/SimpleHiddenTest.java" )
620+ . by_name ( "toplevel/some_course/MavenExercise/src/test/java/SimpleHiddenTest.java" )
621+ . unwrap ( ) ;
622+ archive
623+ . by_name ( "toplevel/some_course/MavenExercise/pom.xml" )
588624 . unwrap ( ) ;
589- archive. by_name ( "toplevel/pom.xml" ) . unwrap ( ) ;
590625 }
591626
592627 #[ test]
@@ -619,10 +654,10 @@ mod test {
619654
620655 // visible tests included, hidden test isn't
621656 assert ! ( output_extracted
622- . join( "src/test/java/SimpleTest.java" )
657+ . join( "some_course/MavenExercise/ src/test/java/SimpleTest.java" )
623658 . exists( ) ) ;
624659 assert ! ( !output_extracted
625- . join( "src/test/java/SimpleHiddenTest.java" )
660+ . join( "some_course/MavenExercise/ src/test/java/SimpleHiddenTest.java" )
626661 . exists( ) ) ;
627662 }
628663
@@ -632,9 +667,11 @@ mod test {
632667 let ( _temp, output) = generic_submission ( MAKE_CLONE , MAKE_ZIP ) ;
633668
634669 // expected files
635- assert ! ( output. join( "src/main.c" ) . exists( ) ) ;
636- assert ! ( output. join( "test/test_source.c" ) . exists( ) ) ;
637- assert ! ( output. join( "Makefile" ) . exists( ) ) ;
670+ assert ! ( output. join( "some_course/MakeExercise/src/main.c" ) . exists( ) ) ;
671+ assert ! ( output
672+ . join( "some_course/MakeExercise/test/test_source.c" )
673+ . exists( ) ) ;
674+ assert ! ( output. join( "some_course/MakeExercise/Makefile" ) . exists( ) ) ;
638675 }
639676
640677 #[ test]
@@ -643,9 +680,15 @@ mod test {
643680 let ( _temp, output) = generic_submission ( PYTHON_CLONE , PYTHON_ZIP ) ;
644681
645682 // expected files
646- assert ! ( output. join( "src/__main__.py" ) . exists( ) ) ;
647- assert ! ( output. join( "test/test_greeter.py" ) . exists( ) ) ;
683+ assert ! ( output
684+ . join( "some_course/PythonExercise/src/__main__.py" )
685+ . exists( ) ) ;
686+ assert ! ( output
687+ . join( "some_course/PythonExercise/test/test_greeter.py" )
688+ . exists( ) ) ;
648689 // assert!(output.join("tmc/points.py").exists()); // not included?
649- assert ! ( output. join( "__init__.py" ) . exists( ) ) ;
690+ assert ! ( output
691+ . join( "some_course/PythonExercise/__init__.py" )
692+ . exists( ) ) ;
650693 }
651694}
0 commit comments