Skip to content

Commit a3c7bdf

Browse files
authored
Merge pull request #203 from rage/sandbox-image
Add sandbox info to compress-project return value
2 parents aea91d9 + 001e88a commit a3c7bdf

File tree

28 files changed

+204
-229
lines changed

28 files changed

+204
-229
lines changed

crates/bindings/tmc-langs-node/src/de.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ impl<'x, 'd, 'a, 'j, C: Context<'j>> serde::de::Deserializer<'x>
9797
let len = prop_names.len(self.cx);
9898
if len != 1 {
9999
return Err(LibError::InvalidKeyType(format!(
100-
"object key with {} properties",
101-
len
100+
"object key with {len} properties"
102101
)));
103102
}
104103
let key: Handle<JsString> = prop_names.get(self.cx, 0)?;

crates/bindings/tmc-langs-node/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn prepare_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
190190
submission_compression: Compression,
191191
extract_submission_naively: bool,
192192
tmc_param: Vec<(String, Vec<String>)>,
193-
top_level_dir_name: Option<String>
193+
no_archive_prefix: bool
194194
);
195195

196196
let mut tmc_params = tmc_langs::TmcParams::new();
@@ -220,7 +220,7 @@ fn prepare_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
220220
extract_naively: extract_submission_naively,
221221
},
222222
&output_path,
223-
top_level_dir_name,
223+
no_archive_prefix,
224224
tmc_params,
225225
&clone_path,
226226
stub_archive_path.as_deref().map(|p| (p, stub_compression)),
@@ -899,7 +899,7 @@ mod test {
899899
);
900900

901901
let s = Command::new("npm")
902-
.args(&["run", "jest"])
902+
.args(["run", "jest"])
903903
.output()
904904
.expect("running jest failed");
905905
println!("stdout: {}", String::from_utf8_lossy(&s.stdout));

crates/helpers/tmc-server-mock/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ use serde_json::json;
99
pub fn mock_config(projects_dir: &str) -> String {
1010
format!(
1111
r#"
12-
projects-dir = '{}'
12+
projects-dir = '{projects_dir}'
1313
setting = "value"
14-
"#,
15-
projects_dir
14+
"#
1615
)
1716
}
1817

crates/plugins/csharp/src/plugin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl CSharpPlugin {
135135
/// Contains a src directory which contains a .csproj file (which may be inside a subdirectory).
136136
impl LanguagePlugin for CSharpPlugin {
137137
const PLUGIN_NAME: &'static str = "csharp";
138+
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-csharp:latest";
138139
const LINE_COMMENT: &'static str = "//";
139140
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = Some(("/*", "*/"));
140141
type StudentFilePolicy = CSharpStudentFilePolicy;
@@ -213,6 +214,7 @@ impl LanguagePlugin for CSharpPlugin {
213214
for (key, value) in json {
214215
tests.push(TestDesc::new(key, value));
215216
}
217+
216218
Ok(ExerciseDesc {
217219
name: exercise_name,
218220
tests,

crates/plugins/java/src/ant_plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl AntPlugin {
7070
/// Contains src and test directories.
7171
impl LanguagePlugin for AntPlugin {
7272
const PLUGIN_NAME: &'static str = "apache-ant";
73+
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-java:latest";
7374
const LINE_COMMENT: &'static str = "//";
7475
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = Some(("/*", "*/"));
7576
type StudentFilePolicy = AntStudentFilePolicy;
@@ -287,7 +288,7 @@ impl JavaPlugin for AntPlugin {
287288
arguments.push(format!("-Dtmc.test_class_dir={}", test_dir.display()));
288289
// we want to use path relative to the exercise path for the java command,
289290
// and a path relative to the current directory for the rest of the program
290-
arguments.push(format!("-Dtmc.results_file={}", result_file_name));
291+
arguments.push(format!("-Dtmc.results_file={result_file_name}"));
291292
// TODO: endorsed libs?
292293
let endorsed_libs_path = path.join("lib/endorsed");
293294
if endorsed_libs_path.exists() {

crates/plugins/java/src/java_plugin.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ mod test {
335335

336336
impl LanguagePlugin for Stub {
337337
const PLUGIN_NAME: &'static str = "stub";
338+
const DEFAULT_SANDBOX_IMAGE: &'static str = "stub-image";
338339
const LINE_COMMENT: &'static str = "//";
339340
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = Some(("/*", "*/"));
340341
type StudentFilePolicy = tmc_langs_framework::EverythingIsStudentFilePolicy;
@@ -390,10 +391,8 @@ mod test {
390391
}
391392
fn get_project_class_path(&self, path: &Path) -> Result<String, JavaError> {
392393
let path = path.to_str().unwrap();
393-
let cp = format!(
394-
"{1}/lib/edu-test-utils-0.4.1.jar{0}{1}/lib/junit-4.10.jar",
395-
SEPARATOR, path
396-
);
394+
let cp =
395+
format!("{path}/lib/edu-test-utils-0.4.1.jar{SEPARATOR}{path}/lib/junit-4.10.jar");
397396
Ok(cp)
398397
}
399398

crates/plugins/java/src/maven_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl MavenPlugin {
9999
/// Contains pom.xml file
100100
impl LanguagePlugin for MavenPlugin {
101101
const PLUGIN_NAME: &'static str = "apache-maven";
102+
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-java:latest";
102103
const LINE_COMMENT: &'static str = "//";
103104
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = Some(("/*", "*/"));
104105
type StudentFilePolicy = MavenStudentFilePolicy;

crates/plugins/make/src/plugin.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ impl MakePlugin {
2929

3030
/// Parses tmc_available_points.txt which is output by the TMC tests and
3131
/// contains lines like "[test] [test_one] 1.1 1.2 1.3" = "[type] [name] points".
32-
fn parse_exercise_desc(
33-
&self,
34-
available_points: &Path,
35-
exercise_name: String,
36-
) -> Result<ExerciseDesc, MakeError> {
32+
fn parse_available_points(&self, available_points: &Path) -> Result<Vec<TestDesc>, MakeError> {
3733
// "[test] [test_one] 1.1 1.2 1.3" = "[type] [name] points"
3834
// TODO: use parser lib
3935
#[allow(clippy::unwrap_used)]
@@ -60,11 +56,7 @@ impl MakePlugin {
6056
}
6157
}
6258
}
63-
64-
Ok(ExerciseDesc {
65-
name: exercise_name,
66-
tests,
67-
})
59+
Ok(tests)
6860
}
6961

7062
/// Runs tests with or without valgrind according to the argument.
@@ -123,6 +115,7 @@ impl MakePlugin {
123115
/// Contains a src directory and a Makefile file
124116
impl LanguagePlugin for MakePlugin {
125117
const PLUGIN_NAME: &'static str = "make";
118+
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-make:latest";
126119
const LINE_COMMENT: &'static str = "//";
127120
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = Some(("/*", "*/"));
128121
type StudentFilePolicy = MakeStudentFilePolicy;
@@ -140,7 +133,11 @@ impl LanguagePlugin for MakePlugin {
140133
return MakeError::CantFindAvailablePoints(available_points_path).into();
141134
}
142135

143-
Ok(self.parse_exercise_desc(&available_points_path, exercise_name)?)
136+
let tests = self.parse_available_points(&available_points_path)?;
137+
Ok(ExerciseDesc {
138+
name: exercise_name,
139+
tests,
140+
})
144141
}
145142

146143
fn run_tests_with_timeout(
@@ -229,9 +226,7 @@ impl LanguagePlugin for MakePlugin {
229226

230227
// parse available points into a mapping from test name to test point list
231228
let available_points_path = base_test_path.join("tmc_available_points.txt");
232-
let tests = self
233-
.parse_exercise_desc(&available_points_path, "unused".to_string())?
234-
.tests;
229+
let tests = self.parse_available_points(&available_points_path)?;
235230
let mut ids_to_points = HashMap::new();
236231
for test in tests {
237232
ids_to_points.insert(test.name, test.points);
@@ -503,11 +498,9 @@ test [invalid] point6
503498
);
504499

505500
let plugin = MakePlugin::new();
506-
let exercise_desc = plugin
507-
.parse_exercise_desc(&available_points, "ex".to_string())
508-
.unwrap();
509-
assert_eq!(exercise_desc.tests.len(), 2);
510-
assert_eq!(exercise_desc.tests[0].points.len(), 4);
501+
let exercise_desc = plugin.parse_available_points(&available_points).unwrap();
502+
assert_eq!(exercise_desc.len(), 2);
503+
assert_eq!(exercise_desc[0].points.len(), 4);
511504
}
512505

513506
#[test]

crates/plugins/notests/src/plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ impl NoTestsPlugin {
3838
/// Contains a .tmcproject.yml file that has `no-tests` set to `true`.
3939
impl LanguagePlugin for NoTestsPlugin {
4040
const PLUGIN_NAME: &'static str = "No-Tests";
41+
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-python:latest"; // doesn't really matter, just use Python image
4142
const LINE_COMMENT: &'static str = "//";
4243
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = None;
4344
type StudentFilePolicy = NoTestsStudentFilePolicy;
4445

4546
fn scan_exercise(&self, path: &Path, exercise_name: String) -> Result<ExerciseDesc, TmcError> {
46-
let test_name = format!("{}Test", exercise_name);
47+
let test_name = format!("{exercise_name}Test");
4748
Ok(ExerciseDesc {
4849
name: exercise_name,
4950
tests: vec![TestDesc {

crates/plugins/python3/src/plugin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ impl Python3Plugin {
217217
/// Contains an .ipynb file. This is given lower priority than the prior rule, and if there are multiple .ipynb files, the shallowest directory is returned.
218218
impl LanguagePlugin for Python3Plugin {
219219
const PLUGIN_NAME: &'static str = "python3";
220+
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-python:latest";
220221
const LINE_COMMENT: &'static str = "#";
221222
const BLOCK_COMMENT: Option<(&'static str, &'static str)> = Some(("\"\"\"", "\"\"\""));
222223
type StudentFilePolicy = Python3StudentFilePolicy;
@@ -243,7 +244,8 @@ impl LanguagePlugin for Python3Plugin {
243244
if available_points_json.exists() {
244245
file_util::remove_file(&available_points_json)?;
245246
}
246-
Ok(ExerciseDesc::new(exercise_name, test_descs_res?))
247+
let tests = test_descs_res?;
248+
Ok(ExerciseDesc::new(exercise_name, tests))
247249
}
248250

249251
fn run_tests_with_timeout(

0 commit comments

Comments
 (0)