Skip to content

Commit 9af5b98

Browse files
committed
Update deps
1 parent 184ef64 commit 9af5b98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+496
-392
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ authors = [
1919
"University of Helsinki <[email protected]>",
2020
"Daniel Martinez <[email protected]>",
2121
]
22-
edition = "2021"
22+
edition = "2024"
2323
license = "MIT OR Apache-2.0"
24-
rust-version = "1.70.0"
24+
rust-version = "1.85.0"
2525
version = "0.37.2"
2626

2727
[workspace.dependencies]

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

+54-40
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ use std::{
1616
};
1717
use thiserror::Error;
1818
use tmc_langs::{
19-
file_util,
19+
Compression, Credentials, DownloadOrUpdateCourseExercisesResult, LangsError, Language,
20+
PrepareSubmission, TmcConfig, file_util,
2021
tmc::{
22+
TestMyCodeClient, TestMyCodeClientError,
2123
request::FeedbackAnswer,
2224
response::{NewSubmission, SubmissionFinished},
23-
TestMyCodeClient, TestMyCodeClientError,
2425
},
25-
Compression, Credentials, DownloadOrUpdateCourseExercisesResult, LangsError, Language,
26-
PrepareSubmission, TmcConfig,
2726
};
2827

2928
#[derive(Debug, Error)]
@@ -82,12 +81,6 @@ pub fn init_logging(mut cx: FunctionContext) -> JsResult<JsNull> {
8281
Ok(cx.null())
8382
}
8483

85-
pub fn set_env(mut cx: FunctionContext) -> JsResult<JsNull> {
86-
parse_args!(cx, key: String, val: String);
87-
env::set_var(key, val);
88-
Ok(cx.null())
89-
}
90-
9184
fn checkstyle(mut cx: FunctionContext) -> JsResult<JsValue> {
9285
parse_args!(cx, exercise_path: PathBuf, locale: String);
9386
lock!(cx, exercise_path);
@@ -304,7 +297,9 @@ fn download_model_solution(mut cx: FunctionContext) -> JsResult<JsValue> {
304297
);
305298

306299
let res = with_client(client_name, client_version, |client| {
307-
Ok(client.download_model_solution(exercise_id, &target)?)
300+
Ok(client
301+
.download_model_solution(exercise_id, &target)
302+
.map_err(Box::new)?)
308303
});
309304
convert_res(&mut cx, res)
310305
}
@@ -398,7 +393,7 @@ fn get_course_details(mut cx: FunctionContext) -> JsResult<JsValue> {
398393
);
399394

400395
let res = with_client(client_name, client_version, |client| {
401-
Ok(client.get_course_details(course_id)?)
396+
Ok(client.get_course_details(course_id).map_err(Box::new)?)
402397
});
403398
convert_res(&mut cx, res)
404399
}
@@ -412,7 +407,7 @@ fn get_course_exercises(mut cx: FunctionContext) -> JsResult<JsValue> {
412407
);
413408

414409
let res = with_client(client_name, client_version, |client| {
415-
Ok(client.get_course_exercises(course_id)?)
410+
Ok(client.get_course_exercises(course_id).map_err(Box::new)?)
416411
});
417412
convert_res(&mut cx, res)
418413
}
@@ -426,7 +421,7 @@ fn get_course_settings(mut cx: FunctionContext) -> JsResult<JsValue> {
426421
);
427422

428423
let res = with_client(client_name, client_version, |client| {
429-
Ok(client.get_course(course_id)?)
424+
Ok(client.get_course(course_id).map_err(Box::new)?)
430425
});
431426
convert_res(&mut cx, res)
432427
}
@@ -440,7 +435,7 @@ fn get_courses(mut cx: FunctionContext) -> JsResult<JsValue> {
440435
);
441436

442437
let res = with_client(client_name, client_version, |client| {
443-
Ok(client.list_courses(&organization)?)
438+
Ok(client.list_courses(&organization).map_err(Box::new)?)
444439
});
445440
convert_res(&mut cx, res)
446441
}
@@ -454,7 +449,7 @@ fn get_exercise_details(mut cx: FunctionContext) -> JsResult<JsValue> {
454449
);
455450

456451
let res = with_client(client_name, client_version, |client| {
457-
Ok(client.get_exercise_details(exercise_id)?)
452+
Ok(client.get_exercise_details(exercise_id).map_err(Box::new)?)
458453
});
459454
convert_res(&mut cx, res)
460455
}
@@ -468,7 +463,9 @@ fn get_exercise_submissions(mut cx: FunctionContext) -> JsResult<JsValue> {
468463
);
469464

470465
let res = with_client(client_name, client_version, |client| {
471-
Ok(client.get_exercise_submissions_for_current_user(exercise_id)?)
466+
Ok(client
467+
.get_exercise_submissions_for_current_user(exercise_id)
468+
.map_err(Box::new)?)
472469
});
473470
convert_res(&mut cx, res)
474471
}
@@ -484,7 +481,9 @@ fn get_exercise_updates(mut cx: FunctionContext) -> JsResult<JsValue> {
484481

485482
let map = exercise.into_iter().collect();
486483
let res = with_client(client_name, client_version, |client| {
487-
Ok(client.get_exercise_updates(course_id, map)?)
484+
Ok(client
485+
.get_exercise_updates(course_id, map)
486+
.map_err(Box::new)?)
488487
});
489488
convert_res(&mut cx, res)
490489
}
@@ -498,7 +497,7 @@ fn get_organization(mut cx: FunctionContext) -> JsResult<JsValue> {
498497
);
499498

500499
let res = with_client(client_name, client_version, |client| {
501-
Ok(client.get_organization(&organization)?)
500+
Ok(client.get_organization(&organization).map_err(Box::new)?)
502501
});
503502
convert_res(&mut cx, res)
504503
}
@@ -507,7 +506,7 @@ fn get_organizations(mut cx: FunctionContext) -> JsResult<JsValue> {
507506
parse_args!(cx, client_name: String, client_version: String);
508507

509508
let res = with_client(client_name, client_version, |client| {
510-
Ok(client.get_organizations()?)
509+
Ok(client.get_organizations().map_err(Box::new)?)
511510
});
512511
convert_res(&mut cx, res)
513512
}
@@ -521,7 +520,7 @@ fn get_unread_reviews(mut cx: FunctionContext) -> JsResult<JsValue> {
521520
);
522521

523522
let res = with_client(client_name, client_version, |client| {
524-
Ok(client.get_unread_reviews(course_id)?)
523+
Ok(client.get_unread_reviews(course_id).map_err(Box::new)?)
525524
});
526525
convert_res(&mut cx, res)
527526
}
@@ -600,7 +599,9 @@ fn mark_review_as_read(mut cx: FunctionContext) -> JsResult<JsValue> {
600599
);
601600

602601
let res = with_client(client_name, client_version, |client| {
603-
Ok(client.mark_review_as_read(course_id, review_id)?)
602+
Ok(client
603+
.mark_review_as_read(course_id, review_id)
604+
.map_err(Box::new)?)
604605
});
605606
convert_res(&mut cx, res)
606607
}
@@ -619,7 +620,9 @@ fn paste(mut cx: FunctionContext) -> JsResult<JsValue> {
619620

620621
let locale = locale.map(|l| Language::from_639_3(&l).expect("Invalid locale"));
621622
let res = with_client(client_name, client_version, |client| {
622-
Ok(client.paste(exercise_id, &submission_path, paste_message, locale)?)
623+
Ok(client
624+
.paste(exercise_id, &submission_path, paste_message, locale)
625+
.map_err(Box::new)?)
623626
});
624627
convert_res(&mut cx, res)
625628
}
@@ -638,12 +641,14 @@ fn request_code_review(mut cx: FunctionContext) -> JsResult<JsValue> {
638641

639642
let locale = Language::from_639_3(&locale).expect("Invalid locale");
640643
let res = with_client(client_name, client_version, |client| {
641-
Ok(client.request_code_review(
642-
exercise_id,
643-
&submission_path,
644-
message_for_reviewer,
645-
Some(locale),
646-
)?)
644+
Ok(client
645+
.request_code_review(
646+
exercise_id,
647+
&submission_path,
648+
message_for_reviewer,
649+
Some(locale),
650+
)
651+
.map_err(Box::new)?)
647652
});
648653
convert_res(&mut cx, res)
649654
}
@@ -661,7 +666,9 @@ fn reset_exercise(mut cx: FunctionContext) -> JsResult<JsValue> {
661666

662667
let res = with_client(client_name, client_version, |client| {
663668
if save_old_state {
664-
client.submit(exercise_id, &exercise_path, None)?;
669+
client
670+
.submit(exercise_id, &exercise_path, None)
671+
.map_err(Box::new)?;
665672
}
666673
tmc_langs::reset(client, exercise_id, &exercise_path)
667674
});
@@ -685,7 +692,9 @@ fn send_feedback(mut cx: FunctionContext) -> JsResult<JsValue> {
685692
})
686693
.collect();
687694
let res = with_client(client_name, client_version, |client| {
688-
Ok(client.send_feedback(submission_id, feedback)?)
695+
Ok(client
696+
.send_feedback(submission_id, feedback)
697+
.map_err(Box::new)?)
689698
});
690699
convert_res(&mut cx, res)
691700
}
@@ -708,15 +717,19 @@ fn submit(mut cx: FunctionContext) -> JsResult<JsValue> {
708717

709718
let locale = locale.map(|l| Language::from_639_3(&l).expect("Invalid locale"));
710719
let temp = with_client(client_name, client_version, |client| {
711-
let new_submission = client.submit(exercise_id, &submission_path, locale)?;
720+
let new_submission = client
721+
.submit(exercise_id, &submission_path, locale)
722+
.map_err(Box::new)?;
712723
if dont_block {
713724
Ok(Temp::NewSubmission(new_submission))
714725
} else {
715726
let submission_url = new_submission
716727
.submission_url
717728
.parse()
718729
.expect("Failed to parse submission URL");
719-
let finished = client.wait_for_submission_at(submission_url)?;
730+
let finished = client
731+
.wait_for_submission_at(submission_url)
732+
.map_err(Box::new)?;
720733
Ok(Temp::Finished(Box::new(finished)))
721734
}
722735
})
@@ -747,7 +760,9 @@ fn wait_for_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
747760
);
748761

749762
let res = with_client(client_name, client_version, |client| {
750-
Ok(client.wait_for_submission(submission_id)?)
763+
Ok(client
764+
.wait_for_submission(submission_id)
765+
.map_err(Box::new)?)
751766
});
752767
convert_res(&mut cx, res)
753768
}
@@ -826,7 +841,6 @@ fn unset_setting(mut cx: FunctionContext) -> JsResult<JsValue> {
826841
#[neon::main]
827842
fn main(mut cx: ModuleContext) -> NeonResult<()> {
828843
cx.export_function("initLogging", init_logging)?;
829-
cx.export_function("setEnv", set_env)?;
830844

831845
cx.export_function("checkstyle", checkstyle)?;
832846
cx.export_function("clean", clean)?;
@@ -887,7 +901,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
887901

888902
#[cfg(test)]
889903
mod test {
890-
use std::{env, process::Command};
904+
use std::process::Command;
891905
use tmc_server_mock::mockito::Server;
892906

893907
fn init() {
@@ -905,13 +919,13 @@ mod test {
905919
init();
906920
let mut server = Server::new();
907921
tmc_server_mock::mock_all(&mut server);
908-
env::set_var(
909-
"TMC_LANGS_MOCK_SERVER_ADDR",
910-
format!("http://{}", server.host_with_port()),
911-
);
912922

913923
let s = Command::new("npm")
914924
.args(["run", "jest"])
925+
.env(
926+
"TMC_LANGS_MOCK_SERVER_ADDR",
927+
format!("http://{}", server.host_with_port()),
928+
)
915929
.output()
916930
.expect("running jest failed");
917931
println!("stdout: {}", String::from_utf8_lossy(&s.stdout));

crates/plugins/csharp/src/plugin.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! An implementation of LanguagePlugin for C#.
22
3-
use crate::{cs_test_result::CSTestResult, policy::CSharpStudentFilePolicy, CSharpError};
3+
use crate::{CSharpError, cs_test_result::CSTestResult, policy::CSharpStudentFilePolicy};
44
use std::{
55
collections::{HashMap, HashSet},
66
env,
@@ -11,12 +11,12 @@ use std::{
1111
time::Duration,
1212
};
1313
use tmc_langs_framework::{
14-
nom::{bytes, character, combinator, sequence, IResult, Parser},
15-
nom_language::error::VerboseError,
1614
Archive, CommandError, ExerciseDesc, Language, LanguagePlugin, RunResult, RunStatus,
1715
StyleValidationResult, StyleValidationStrategy, TestDesc, TestResult, TmcCommand, TmcError,
16+
nom::{IResult, Parser, bytes, character, combinator, sequence},
17+
nom_language::error::VerboseError,
1818
};
19-
use tmc_langs_util::{deserialize, file_util, parse_util, path_util, FileError};
19+
use tmc_langs_util::{deserialize, file_util, parse_util, path_util};
2020
use walkdir::WalkDir;
2121
use zip::ZipArchive;
2222

@@ -43,12 +43,7 @@ impl CSharpPlugin {
4343
if let Some(parent) = target_file_path.parent() {
4444
file_util::create_dir_all(parent)?;
4545
}
46-
47-
let file_path = PathBuf::from(file.name());
48-
let bytes: Vec<u8> = file
49-
.bytes()
50-
.collect::<Result<Vec<_>, _>>()
51-
.map_err(|e| FileError::FileRead(file_path, e))?;
46+
let bytes = file_util::read_reader(file)?;
5247
file_util::write_to_file(bytes, target_file_path)?;
5348
}
5449
}
@@ -91,7 +86,7 @@ impl CSharpPlugin {
9186
/// Returns the path to the TMC C# runner in the cache. If TMC_CSHARP_BOOTSTRAP_PATH is set, it is returned instead.
9287
fn get_bootstrap_path() -> Result<PathBuf, CSharpError> {
9388
if let Ok(var) = env::var("TMC_CSHARP_BOOTSTRAP_PATH") {
94-
log::debug!("using bootstrap path TMC_CSHARP_BOOTSTRAP_PATH={}", var);
89+
log::debug!("using bootstrap path TMC_CSHARP_BOOTSTRAP_PATH={var}");
9590
Ok(PathBuf::from(var))
9691
} else {
9792
let runner_path = Self::get_or_init_runner_dir()?;
@@ -253,8 +248,8 @@ impl LanguagePlugin for CSharpPlugin {
253248
let stdout = String::from_utf8_lossy(&output.stdout);
254249
let stderr = String::from_utf8_lossy(&output.stderr);
255250
if !output.status.success() {
256-
log::warn!("stdout: {}", stdout);
257-
log::error!("stderr: {}", stderr);
251+
log::warn!("stdout: {stdout}");
252+
log::error!("stderr: {stderr}");
258253
let mut logs = HashMap::new();
259254
logs.insert("stdout".to_string(), stdout.into_owned());
260255
logs.insert("stderr".to_string(), stderr.into_owned());
@@ -265,8 +260,8 @@ impl LanguagePlugin for CSharpPlugin {
265260
});
266261
}
267262

268-
log::trace!("stdout: {}", stdout);
269-
log::debug!("stderr: {}", stderr);
263+
log::trace!("stdout: {stdout}");
264+
log::debug!("stderr: {stderr}");
270265

271266
if !test_results_path.exists() {
272267
return Err(CSharpError::MissingTestResults {
@@ -479,9 +474,10 @@ mod test {
479474
init();
480475

481476
let path = CSharpPlugin::get_bootstrap_path().unwrap();
482-
assert!(path
483-
.to_string_lossy()
484-
.contains("TestMyCode.CSharp.Bootstrap.dll"));
477+
assert!(
478+
path.to_string_lossy()
479+
.contains("TestMyCode.CSharp.Bootstrap.dll")
480+
);
485481
}
486482

487483
#[test]
@@ -634,11 +630,12 @@ mod test {
634630
assert_eq!(res.status, RunStatus::CompileFailed);
635631
assert!(!res.logs.is_empty());
636632
log::debug!("{:?}", res.logs.get("stdout"));
637-
assert!(res
638-
.logs
639-
.get("stdout")
640-
.unwrap()
641-
.contains("This is a compile error"));
633+
assert!(
634+
res.logs
635+
.get("stdout")
636+
.unwrap()
637+
.contains("This is a compile error")
638+
);
642639
}
643640

644641
#[test]

0 commit comments

Comments
 (0)