Skip to content

Commit 6f7bc20

Browse files
committed
hir and edition test
1 parent 5269992 commit 6f7bc20

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

orchestrator/src/coordinator.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ async fn modify_cargo_toml(
319319
let cargo_toml = String::from_utf8(cargo_toml.0)?;
320320
let cargo_toml = toml::from_str(&cargo_toml)?;
321321

322-
let cargo_toml = modify_cargo_toml::set_edition(cargo_toml, edition.as_cargo_toml_key());
322+
let cargo_toml = modify_cargo_toml::set_edition(cargo_toml, edition.to_cargo_toml_key());
323323

324324
let cargo_toml = toml::to_string(&cargo_toml)?;
325325
let cargo_toml = cargo_toml.into_bytes();
@@ -795,6 +795,23 @@ mod tests {
795795
}
796796
}
797797

798+
fn new_compile_hir_request() -> CompileRequest {
799+
new_compile_hir_request_for(Edition::Rust2021)
800+
}
801+
802+
fn new_compile_hir_request_for(edition: Edition) -> CompileRequest {
803+
CompileRequest {
804+
target: CompileTarget::Hir,
805+
channel: Channel::Beta,
806+
crate_type: CrateType::Library(LibraryType::Lib),
807+
mode: Mode::Release,
808+
edition,
809+
tests: false,
810+
backtrace: false,
811+
code: r#"pub fn sub(a: u8, b: u8) -> u8 { a - b }"#.to_owned(),
812+
}
813+
}
814+
798815
fn new_compile_llvm_ir_request() -> CompileRequest {
799816
CompileRequest {
800817
target: CompileTarget::LlvmIr,
@@ -879,6 +896,30 @@ mod tests {
879896
Ok(())
880897
}
881898

899+
#[tokio::test]
900+
#[snafu::report]
901+
async fn test_compile_edition() -> Result<()> {
902+
for edition in Edition::ALL {
903+
let coordinator = new_coordinator()?;
904+
905+
let response = coordinator
906+
.compile(new_compile_hir_request_for(edition))
907+
.with_timeout()
908+
.await
909+
.unwrap();
910+
911+
let prelude = format!("std::prelude::rust_{}", edition.to_str());
912+
913+
assert!(response.success, "stderr: {}", response.stderr);
914+
assert_contains!(response.code, &prelude);
915+
916+
coordinator.shutdown().await?;
917+
}
918+
919+
Ok(())
920+
}
921+
922+
882923
#[tokio::test]
883924
#[snafu::report]
884925
async fn test_compile_assembly() -> Result<()> {
@@ -904,6 +945,25 @@ mod tests {
904945
Ok(())
905946
}
906947

948+
#[tokio::test]
949+
#[snafu::report]
950+
async fn test_compile_hir() -> Result<()> {
951+
let coordinator = new_coordinator()?;
952+
953+
let response = coordinator
954+
.compile(new_compile_hir_request())
955+
.with_timeout()
956+
.await
957+
.unwrap();
958+
959+
assert!(response.success, "stderr: {}", response.stderr);
960+
assert_contains!(response.code, "extern crate std");
961+
962+
coordinator.shutdown().await?;
963+
964+
Ok(())
965+
}
966+
907967
#[tokio::test]
908968
#[snafu::report]
909969
async fn test_compile_llvm_ir() -> Result<()> {

orchestrator/src/sandbox.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@ pub enum Edition {
6262
}
6363

6464
impl Edition {
65-
pub(crate) fn as_cargo_toml_key(&self) -> &'static str {
65+
#[cfg(test)]
66+
pub(crate) const ALL: [Self; 3] = [Self::Rust2015, Self::Rust2018, Self::Rust2021];
67+
68+
pub(crate) fn to_str(&self) -> &'static str {
6669
match self {
6770
Edition::Rust2015 => "2015",
6871
Edition::Rust2018 => "2018",
6972
Edition::Rust2021 => "2021",
7073
}
7174
}
75+
76+
pub(crate) fn to_cargo_toml_key(&self) -> &'static str {
77+
self.to_str()
78+
}
7279
}
7380

7481
#[derive(Debug, Copy, Clone, PartialEq, Eq)]

0 commit comments

Comments
 (0)