Skip to content

Commit 47d974e

Browse files
committed
fail on no test results
1 parent c52db04 commit 47d974e

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

tmc-langs-framework/src/plugin.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
pub use isolang::Language;
44
pub use tmc_langs_abstraction::{Strategy, ValidationError, ValidationResult};
55

6-
use super::domain::{ExerciseDesc, ExercisePackagingConfiguration, RunResult, TmcProjectYml};
6+
use super::domain::{
7+
ExerciseDesc, ExercisePackagingConfiguration, RunResult, RunStatus, TestResult, TmcProjectYml,
8+
};
79
use super::io::{submission_processing, zip};
810
use super::policy::StudentFilePolicy;
911
use super::Result;
1012
use log::debug;
11-
use std::collections::HashSet;
13+
use std::collections::{HashMap, HashSet};
1214
use std::path::{Path, PathBuf};
1315
use std::time::Duration;
1416
use walkdir::WalkDir;
@@ -67,7 +69,25 @@ pub trait LanguagePlugin {
6769
.get_tmc_project_yml()
6870
.ok()
6971
.and_then(|t| t.tests_timeout_ms.map(Duration::from_millis));
70-
self.run_tests_with_timeout(path, timeout)
72+
let result = self.run_tests_with_timeout(path, timeout)?;
73+
74+
// override success on no test cases
75+
if result.status == RunStatus::Passed && result.test_results.is_empty() {
76+
Ok(RunResult {
77+
status: RunStatus::TestsFailed,
78+
test_results: vec![TestResult {
79+
name: "Tests found test".to_string(),
80+
successful: true,
81+
points: vec![],
82+
message: "No tests found.\nTry submitting the exercise to the server."
83+
.to_string(),
84+
exception: vec![],
85+
}],
86+
logs: HashMap::new(),
87+
})
88+
} else {
89+
Ok(result)
90+
}
7191
}
7292

7393
/// Runs the tests for the exercise with the given timeout.
@@ -197,7 +217,7 @@ mod test {
197217

198218
impl StudentFilePolicy for MockPolicy {
199219
fn get_config_file_parent_path(&self) -> &Path {
200-
unimplemented!()
220+
Path::new("")
201221
}
202222
fn is_student_source_file(&self, _path: &Path) -> bool {
203223
unimplemented!()
@@ -209,7 +229,7 @@ mod test {
209229
type StudentFilePolicy = MockPolicy;
210230

211231
fn get_student_file_policy(_project_path: &Path) -> Self::StudentFilePolicy {
212-
unimplemented!()
232+
Self::StudentFilePolicy {}
213233
}
214234

215235
fn scan_exercise(&self, _path: &Path, _exercise_name: String) -> Result<ExerciseDesc> {
@@ -221,7 +241,11 @@ mod test {
221241
_path: &Path,
222242
_timeout: Option<Duration>,
223243
) -> Result<RunResult> {
224-
unimplemented!()
244+
Ok(RunResult {
245+
status: RunStatus::Passed,
246+
test_results: vec![],
247+
logs: HashMap::new(),
248+
})
225249
}
226250

227251
fn is_exercise_type_correct(path: &Path) -> bool {
@@ -299,4 +323,12 @@ extra_exercise_files:
299323
.exercise_file_paths
300324
.contains(&PathBuf::from("test/OtherTest.java")));
301325
}
326+
327+
#[test]
328+
fn empty_run_result_is_err() {
329+
let plugin = MockPlugin {};
330+
let res = plugin.run_tests(Path::new("")).unwrap();
331+
assert_eq!(res.status, RunStatus::TestsFailed);
332+
assert_eq!(res.test_results[0].name, "Tests found test")
333+
}
302334
}

0 commit comments

Comments
 (0)