Skip to content

Commit d76d692

Browse files
committed
fix env vars in tests
1 parent cb830c1 commit d76d692

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

tmc-langs-cli/src/main.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn run() -> Result<()> {
224224
.required(true)
225225
.takes_value(true)))
226226

227-
.subcommand(SubCommand::with_name("paste-with-comment")
227+
.subcommand(SubCommand::with_name("paste")
228228
.about("Send exercise to pastebin with comment.")
229229
.arg(Arg::with_name("submission-url")
230230
.long("submission-url")
@@ -236,7 +236,6 @@ fn run() -> Result<()> {
236236
.takes_value(true))
237237
.arg(Arg::with_name("paste-message")
238238
.long("paste-message")
239-
.required(true)
240239
.takes_value(true))
241240
.arg(Arg::with_name("locale")
242241
.help("Language as a three letter ISO 639-3 code, e.g. 'eng' or 'fin'.")
@@ -702,22 +701,22 @@ fn run() -> Result<()> {
702701
.context("Failed to get courses")?;
703702

704703
print_result_as_json(&courses)?;
705-
} else if let Some(matches) = matches.subcommand_matches("paste-with-comment") {
704+
} else if let Some(matches) = matches.subcommand_matches("paste") {
706705
let submission_url = matches.value_of("submission-url").unwrap();
707706
let submission_url = into_url(submission_url)?;
708707

709708
let submission_path = matches.value_of("submission-path").unwrap();
710709
let submission_path = Path::new(submission_path);
711-
let paste_message = matches.value_of("paste-message").unwrap();
710+
let paste_message = matches.value_of("paste-message");
712711

713712
let locale = matches.value_of("locale").unwrap();
714713
let locale = into_locale(locale)?;
715714

716715
let new_submission = core
717-
.paste_with_comment(
716+
.paste(
718717
submission_url,
719718
submission_path,
720-
paste_message.to_string(),
719+
paste_message.map(str::to_string),
721720
locale,
722721
)
723722
.context("Failed to get paste with comment")?;

tmc-langs-cli/tests/core_mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fn init() {
99
env::set_var("RUST_LOG", "debug,hyper=warn,tokio_reactor=warn");
1010
}
1111
let _ = env_logger::builder().is_test(true).try_init();
12-
env::set_var("TMC_CORE_CLI_ROOT_URL", mockito::server_url());
13-
env::set_var("TMC_CORE_CLI_CONFIG_DIR", "./");
12+
env::set_var("TMC_LANGS_ROOT_URL", mockito::server_url());
13+
env::set_var("TMC_LANGS_CONFIG_DIR", "./");
1414
}
1515

1616
fn run_cmd(args: &[&str]) -> Output {

tmc-langs-core/src/tmc_core.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ impl TmcCore {
290290
/// "my python solution".to_string(),
291291
/// Language::Eng).unwrap();
292292
/// ```
293-
pub fn paste_with_comment(
293+
pub fn paste(
294294
&self,
295295
submission_url: Url,
296296
submission_path: &Path,
297-
paste_message: String,
297+
paste_message: Option<String>,
298298
locale: Language,
299299
) -> Result<NewSubmission> {
300300
// compress
@@ -687,10 +687,10 @@ mod test {
687687
.create();
688688

689689
let new_submission = core
690-
.paste_with_comment(
690+
.paste(
691691
submission_url,
692692
Path::new("tests/data/exercise"),
693-
"abcdefg".to_string(),
693+
Some("abcdefg".to_string()),
694694
Language::from_639_3("eng").unwrap(),
695695
)
696696
.unwrap();

tmc-langs-core/src/tmc_core/api.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,15 @@ impl TmcCore {
509509
&self,
510510
submission_url: Url,
511511
submission: &Path,
512-
paste_message: String,
512+
paste_message: Option<String>,
513513
locale: Option<Language>,
514514
) -> Result<NewSubmission> {
515515
let mut params = HashMap::new();
516516
params.insert("paste".to_string(), "1".to_string());
517-
params.insert("message_for_paste".to_string(), paste_message);
517+
params.insert(
518+
"message_for_paste".to_string(),
519+
paste_message.unwrap_or_default(), // TODO: can this field be ignored?
520+
);
518521
self.post_submission_with_params(submission_url, submission, Some(params), locale)
519522
}
520523

0 commit comments

Comments
 (0)