Skip to content

Commit f956f3d

Browse files
authored
Merge pull request #116 from rage/refresh-fix
Refresh fix
2 parents 3b241fb + 7846f0c commit f956f3d

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

tmc-langs-framework/src/command.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl TmcCommand {
5858

5959
// starts executing the command
6060
let mut popen = exec.popen().map_err(|e| popen_to_tmc_err(cmd.clone(), e))?;
61-
log::debug!("here {:?} {:?}", popen.stdin, stdin);
6261
let stdin_handle = spawn_writer(popen.stdin.take(), stdin);
6362
let stdout_handle = spawn_reader(popen.stdout.take());
6463
let stderr_handle = spawn_reader(popen.stderr.take());

tmc-langs-framework/src/file_util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ pub fn read_file_to_string<P: AsRef<Path>>(path: P) -> Result<String, FileIo> {
4848
Ok(s)
4949
}
5050

51+
pub fn read_file_to_string_lossy<P: AsRef<Path>>(path: P) -> Result<String, FileIo> {
52+
let path = path.as_ref();
53+
let bytes = read_file(path)?;
54+
let s = String::from_utf8_lossy(&bytes).into_owned();
55+
Ok(s)
56+
}
57+
5158
pub fn create_file<P: AsRef<Path>>(path: P) -> Result<File, FileIo> {
5259
let path = path.as_ref();
5360
if let Some(parent) = path.parent() {

tmc-langs-framework/src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pub trait LanguagePlugin {
424424
let entry = entry?;
425425
if entry.path().is_file() {
426426
log::trace!("parsing points from {}", entry.path().display());
427-
let file_contents = file_util::read_file_to_string(entry.path())?;
427+
let file_contents = file_util::read_file_to_string_lossy(entry.path())?;
428428

429429
// reads any character
430430
let etc_parser = combinator::value(Parse::Other, character::complete::anychar);

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)