Skip to content

Commit 3682618

Browse files
test: reduce and improve tests in src/compile/ir/ (#1049)
1 parent ce6fd7b commit 3682618

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/compile/ir/condition.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ pub mod codegen {
348348
"eq(dependencies.Setup.outputs['x.y'], 'true')"
349349
);
350350
let c = Condition::Custom("eq(variables['X'], '${{ parameters.y }}')".to_string());
351-
assert!(lower_condition(&ctx, &c).is_ok());
351+
assert_eq!(
352+
lower_condition(&ctx, &c).unwrap(),
353+
"eq(variables['X'], '${{ parameters.y }}')"
354+
);
352355
}
353356

354357
#[test]
@@ -403,6 +406,13 @@ mod tests {
403406
#[test]
404407
fn not_boxes_inner() {
405408
let c = Condition::not(Condition::Succeeded);
406-
assert!(matches!(c, Condition::Not(_)));
409+
if let Condition::Not(inner) = c {
410+
assert!(
411+
matches!(*inner, Condition::Succeeded),
412+
"not() must box the supplied inner condition"
413+
);
414+
} else {
415+
panic!("expected Condition::Not");
416+
}
407417
}
408418
}

src/compile/ir/ids.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,24 @@ mod tests {
140140

141141
#[test]
142142
fn distinct_kinds_do_not_share_address_space() {
143-
// Compile-time check: a StageId and a JobId with the same inner
144-
// string are not interchangeable. This won't even compile if
145-
// it isn't true, so the assertion is documentary.
146-
let _stage = StageId::new("Foo").unwrap();
147-
let _job = JobId::new("Foo").unwrap();
148-
// (no assertion needed; the test compiles iff the types are distinct)
143+
use std::any::TypeId;
144+
// Runtime verification that the three ID newtypes are distinct Rust
145+
// types. A coalescing refactor that accidentally unified any two of
146+
// them would be caught here.
147+
assert_ne!(
148+
TypeId::of::<StageId>(),
149+
TypeId::of::<JobId>(),
150+
"StageId and JobId must be distinct types"
151+
);
152+
assert_ne!(
153+
TypeId::of::<StageId>(),
154+
TypeId::of::<StepId>(),
155+
"StageId and StepId must be distinct types"
156+
);
157+
assert_ne!(
158+
TypeId::of::<JobId>(),
159+
TypeId::of::<StepId>(),
160+
"JobId and StepId must be distinct types"
161+
);
149162
}
150163
}

src/compile/ir/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ mod tests {
19581958
let g = Graph::default();
19591959
let yaml = serde_yaml::to_string(&lower_with_graph(&p, &g).unwrap()).unwrap();
19601960
assert!(
1961-
!yaml.contains("name:") || !yaml.contains("should-not-appear"),
1961+
!yaml.contains("name:"),
19621962
"template shape must not emit top-level `name:`, got: {yaml}"
19631963
);
19641964
assert!(
@@ -2004,7 +2004,7 @@ mod tests {
20042004
let g = Graph::default();
20052005
let yaml = serde_yaml::to_string(&lower_with_graph(&p, &g).unwrap()).unwrap();
20062006
assert!(
2007-
!yaml.starts_with("name:"),
2007+
!yaml.contains("name:"),
20082008
"must skip top-level name, got: {yaml}"
20092009
);
20102010
assert!(yaml.contains("jobs:"), "must emit jobs:, got: {yaml}");

0 commit comments

Comments
 (0)