Skip to content

Commit b2957d8

Browse files
committed
Test fixes
1 parent 48f9778 commit b2957d8

File tree

14 files changed

+50
-60
lines changed

14 files changed

+50
-60
lines changed

crates/plugins/csharp/src/policy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ mod test {
3333
fn file_in_binary_dir_is_not_student_file() {
3434
let policy = CSharpStudentFilePolicy::new(Path::new(".")).unwrap();
3535
assert!(!policy.is_student_file(Path::new("src/bin/any/file")));
36-
assert!(!policy.is_student_file(Path::new("obj/any/src/file")));
36+
assert!(!policy.is_student_file(Path::new("obj/any/src/file.cs")));
3737
}
3838

3939
#[test]
40-
fn file_in_src_is_student_file() {
40+
fn cs_file_in_src_is_student_file() {
4141
let policy = CSharpStudentFilePolicy::new(Path::new(".")).unwrap();
42-
assert!(policy.is_student_file(Path::new("src/file")));
43-
assert!(policy.is_student_file(Path::new("src/any/file")));
42+
assert!(policy.is_student_file(Path::new("src/file.cs")));
43+
assert!(policy.is_student_file(Path::new("src/any/file.cs")));
4444
}
4545

4646
#[test]

crates/plugins/java/src/ant_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod test {
3838
#[test]
3939
fn is_not_student_source_file() {
4040
let policy = AntStudentFilePolicy::new(Path::new(".")).unwrap();
41-
assert!(policy.is_student_file(Path::new("src/file")));
41+
assert!(!policy.is_student_file(Path::new("src/file")));
4242
assert!(!policy.is_student_file(Path::new("file")));
4343
assert!(!policy.is_student_file(Path::new("dir/src/file")));
4444
assert!(!policy.is_student_file(Path::new("srca/file")));

crates/plugins/java/src/maven_plugin.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tmc_langs_framework::{
1717
Archive, ExerciseDesc, Language, LanguagePlugin, RunResult, StyleValidationResult, TmcCommand,
1818
TmcError, nom::IResult, nom_language::error::VerboseError,
1919
};
20-
use tmc_langs_util::{file_util, path_util};
20+
use tmc_langs_util::file_util;
2121

2222
const MVN_ARCHIVE: &[u8] = include_bytes!("../deps/apache-maven-3.8.1-bin.tar.gz");
2323
const MVN_PATH_IN_ARCHIVE: &str = "apache-maven-3.8.1"; // the name of the base directory in the maven archive
@@ -137,12 +137,9 @@ impl LanguagePlugin for MavenPlugin {
137137
let next = iter.with_next(|file| {
138138
let file_path = file.path()?;
139139

140-
if file.is_file() && file_path.extension() == Some(OsStr::new("java")) {
141-
// check if java file has src as ancestor
142-
for ancestor in file_path.ancestors() {
143-
if let Some(src_parent) = path_util::get_parent_of_named(ancestor, "src") {
144-
return Ok(Break(Some(src_parent)));
145-
}
140+
if file.is_file() && file_path.file_name() == Some(OsStr::new("pom.xml")) {
141+
if let Some(pom_parent) = file_path.parent() {
142+
return Ok(Break(Some(pom_parent.to_path_buf())));
146143
}
147144
}
148145
Ok(Continue(()))

crates/plugins/java/src/maven_policy.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl StudentFilePolicy for MavenStudentFilePolicy {
2020
}
2121

2222
fn is_non_extra_student_file(&self, path: &Path) -> bool {
23+
// technically pom.xml would need to be included to differentiate between maven and ant projects
2324
path.starts_with("src/main") && path.extension() == Some(OsStr::new("java"))
2425
}
2526
}
@@ -31,8 +32,8 @@ mod test {
3132
#[test]
3233
fn is_student_file() {
3334
let policy = MavenStudentFilePolicy::new(Path::new(".")).unwrap();
34-
assert!(policy.is_student_file(Path::new("src/main/file")));
35-
assert!(policy.is_student_file(Path::new("src/main/dir/file")));
35+
assert!(policy.is_student_file(Path::new("src/main/file.java")));
36+
assert!(policy.is_student_file(Path::new("src/main/dir/file.java")));
3637
}
3738

3839
#[test]

crates/plugins/make/src/policy.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ mod test {
3232
#[test]
3333
fn is_student_file() {
3434
let policy = MakeStudentFilePolicy::new(Path::new(".")).unwrap();
35-
assert!(policy.is_student_file(Path::new("src")));
36-
assert!(policy.is_student_file(Path::new("src/file")));
37-
assert!(policy.is_student_file(Path::new("src/dir/file")));
35+
assert!(policy.is_student_file(Path::new("src/file.c")));
36+
assert!(policy.is_student_file(Path::new("src/file.h")));
37+
assert!(policy.is_student_file(Path::new("src/dir/file.c")));
38+
assert!(policy.is_student_file(Path::new("src/dir/file.h")));
3839
}
3940

4041
#[test]
4142
fn is_not_student_source_file() {
4243
let policy = MakeStudentFilePolicy::new(Path::new(".")).unwrap();
44+
assert!(!policy.is_student_file(Path::new("a.c")));
45+
assert!(!policy.is_student_file(Path::new("a.h")));
4346
assert!(!policy.is_student_file(Path::new("srcc")));
4447
assert!(!policy.is_student_file(Path::new("dir/src/file")));
4548
}

crates/plugins/make/tests/data/valgrind-failing-exercise/src/source.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include "source.h"
3+
#include <stdlib.h>
34

45
int one(void)
56
{

crates/plugins/r/src/policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod test {
3939
init();
4040

4141
let policy = RStudentFilePolicy::new(Path::new(".")).unwrap();
42-
assert!(policy.is_student_file(Path::new("R")));
4342
assert!(policy.is_student_file(Path::new("R/file.R")));
4443
}
4544

@@ -48,6 +47,7 @@ mod test {
4847
init();
4948

5049
let policy = RStudentFilePolicy::new(Path::new(".")).unwrap();
50+
assert!(!policy.is_student_file(Path::new("a.R")));
5151
assert!(!policy.is_student_file(Path::new("dir/R")));
5252
assert!(!policy.is_student_file(Path::new("dir/R/file")));
5353
}

crates/tmc-langs-cli/tests/snapshots/integration__compress_project_tar@make__valgrind-failing-exercise.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ message: compressed project from [PATH] to [PATH]
99
result: executed-command
1010
data:
1111
output-data-kind: compressed-project-hash
12-
output-data: f22f8d2f4502dc8c14e98c9b89f8413b92b219e9ad1aaf6dfc429d1cc177745d
12+
output-data: fb42a43f95667107fd4b696ceadd19cda6595daa2c3afa825f53984fab4baa02

crates/tmc-langs-cli/tests/snapshots/integration__compress_project_zip@make__valgrind-failing-exercise.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ message: compressed project from [PATH] to [PATH]
99
result: executed-command
1010
data:
1111
output-data-kind: compressed-project-hash
12-
output-data: f22f8d2f4502dc8c14e98c9b89f8413b92b219e9ad1aaf6dfc429d1cc177745d
12+
output-data: fb42a43f95667107fd4b696ceadd19cda6595daa2c3afa825f53984fab4baa02

crates/tmc-langs-cli/tests/snapshots/integration__compress_project_zstd@make__valgrind-failing-exercise.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ message: compressed project from [PATH] to [PATH]
99
result: executed-command
1010
data:
1111
output-data-kind: compressed-project-hash
12-
output-data: f22f8d2f4502dc8c14e98c9b89f8413b92b219e9ad1aaf6dfc429d1cc177745d
12+
output-data: fb42a43f95667107fd4b696ceadd19cda6595daa2c3afa825f53984fab4baa02

0 commit comments

Comments
 (0)