Skip to content

Commit 7846f0c

Browse files
committed
improved Hidden test file detection
1 parent d124b82 commit 7846f0c

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

tmc-langs-util/src/task_executor/submission_processing.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use tmc_langs_framework::TmcError;
99
use walkdir::{DirEntry, WalkDir};
1010

1111
lazy_static! {
12-
static ref FILES_TO_SKIP_ALWAYS: Regex =
13-
Regex::new(r"\.tmcrc|^metadata\.yml$|(.*)Hidden(.*)").unwrap();
12+
static ref FILES_TO_SKIP_ALWAYS: Regex = Regex::new(r"\.tmcrc|^metadata\.yml$").unwrap();
1413
static ref NON_TEXT_TYPES: Regex =
1514
Regex::new("class|jar|exe|jpg|jpeg|gif|png|zip|tar|gz|db|bin|csv|tsv|sqlite3|^$").unwrap();
1615
}
@@ -29,13 +28,29 @@ pub fn is_hidden_dir(entry: &DirEntry) -> bool {
2928
skip
3029
}
3130

32-
// Filter for skipping directories on `FILES_TO_SKIP_ALWAYS` or named 'private'
31+
// Filter for skipping directories on `FILES_TO_SKIP_ALWAYS` or named 'private', and files in a 'test' directory that contain 'Hidden' in their name.
3332
fn on_skip_list(entry: &DirEntry) -> bool {
34-
let skip = entry
35-
.file_name()
36-
.to_str()
33+
// check if entry's filename matchees the skip list or is 'private'
34+
let entry_file_name = entry.file_name().to_str();
35+
let on_skip_list = entry_file_name
3736
.map(|s| FILES_TO_SKIP_ALWAYS.is_match(s) || s == "private")
3837
.unwrap_or_default();
38+
39+
// check if the current entry is a file in a "test" directory that contains "Hidden" in its name
40+
let hidden_in_test = if entry.path().is_file() {
41+
if let Some(parent) = entry.path().parent().and_then(|p| p.file_name()) {
42+
parent == "test"
43+
&& entry_file_name
44+
.map(|n| n.contains("Hidden"))
45+
.unwrap_or_default()
46+
} else {
47+
false
48+
}
49+
} else {
50+
false
51+
};
52+
53+
let skip = on_skip_list || hidden_in_test;
3954
if skip {
4055
log::debug!("on skip list: {:?}", entry.path());
4156
}
@@ -383,4 +398,17 @@ extra_student_files:
383398
assert!(conf.extra_student_files[0] == PathBuf::from("test/StudentTest.java"));
384399
assert!(conf.extra_student_files[1] == PathBuf::from("test/OtherTest.java"));
385400
}
401+
402+
#[test]
403+
fn hides_test_hidden_files() {
404+
init();
405+
406+
let temp = tempdir().unwrap();
407+
let temp_path = temp.path();
408+
409+
prepare_solution(Path::new("tests/data/dir"), temp_path).unwrap();
410+
411+
assert!(dbg!(temp_path.join("NotHidden.java")).exists());
412+
assert!(!dbg!(temp_path.join("ActuallyHidden.java")).exists());
413+
}
386414
}

tmc-langs-util/tests/data/dir/test/ActuallyHidden.java

Whitespace-only changes.

0 commit comments

Comments
 (0)