Build the structurizer's test CFGs from one fixture, not six copies
Six `#[cfg(test)] mod`s under structured_emit each carried a private, byte-equivalent `bb(name, lines)` (reject.rs's took a role, which is bb_role). A file without a test module therefore had to grow a seventh copy before it could grow its first test, and a change to how production populates a block carrier had to be found in six places. One `test_support` module owns both constructors; every test module imports them.
This commit is contained in:
1 parent
1b119af370
commit
eac559dcb3
7 files changed
+38
-82
No files matched your search
@@ -461,19 +461,10 @@ pub(in crate::native) fn materialize_construct_routes(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::test_support::bb;
|
||||
use super::*;
|
||||
use crate::native::ir::{LlType, LlValue, TypedValue};
|
||||
use crate::native::tir;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn bb(name: &str, lines: &[&str]) -> BodyBlock {
|
||||
let lines: Vec<String> = lines.iter().map(|line| line.to_string()).collect();
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role: BlockRole::Normal,
|
||||
typed: tir::lower_block_carrier(name, &lines, &HashMap::new()).map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
fn deep_single_owner_nodes() -> Vec<ConstructNode> {
|
||||
vec![
|
||||
|
||||
@@ -71,33 +71,14 @@ pub(in crate::native) use straddle_region::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod construct_tree_fixtures;
|
||||
#[cfg(test)]
|
||||
mod test_support;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::test_support::{bb, bb_role};
|
||||
use super::*;
|
||||
|
||||
fn bb(name: &str, lines: &[&str]) -> BodyBlock {
|
||||
// Populate the typed carrier exactly as production does at split time (the sole substrate).
|
||||
let lines: Vec<String> = lines.iter().map(|s| s.to_string()).collect();
|
||||
let typed = crate::native::tir::lower_block_carrier(
|
||||
name,
|
||||
&lines,
|
||||
&std::collections::HashMap::new(),
|
||||
);
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role: BlockRole::Normal,
|
||||
typed: typed.map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
fn bb_role(name: &str, role: BlockRole, lines: &[&str]) -> BodyBlock {
|
||||
BodyBlock {
|
||||
role,
|
||||
..bb(name, lines)
|
||||
}
|
||||
}
|
||||
|
||||
/// A phi incoming VALUE rendered to a comparable token for the carrier-substrate test assertions
|
||||
/// (the cases these tests use: locals, integer constants, `true`/`false`, `undef`).
|
||||
fn val_str(v: &crate::native::ir::LlValue) -> String {
|
||||
|
||||
@@ -683,20 +683,9 @@ pub(in crate::native) fn renest_cond_phi_shared_own_arm(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::test_support::bb;
|
||||
use super::*;
|
||||
|
||||
fn bb(name: &str, lines: &[&str]) -> BodyBlock {
|
||||
let lines = lines
|
||||
.iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role: BlockRole::Normal,
|
||||
typed: tir::lower_block_carrier(name, &lines, &HashMap::new()).map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r2_own_arm_derivation_is_reject_only() {
|
||||
let admitted = vec![
|
||||
|
||||
@@ -1330,21 +1330,9 @@ pub(in crate::native) fn reject_reason_inner(blocks: &[BodyBlock]) -> Option<Str
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::test_support::bb_role as bb;
|
||||
use super::*;
|
||||
|
||||
fn bb(name: &str, role: BlockRole, lines: &[&str]) -> BodyBlock {
|
||||
let lines = lines
|
||||
.iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role,
|
||||
typed: crate::native::tir::lower_block_carrier(name, &lines, &HashMap::new())
|
||||
.map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plan_self_check_rejects_merge_claimed_by_two_headers() {
|
||||
let blocks = vec![
|
||||
|
||||
@@ -1741,21 +1741,9 @@ fn typed_instruction_count(blocks: &[BodyBlock]) -> usize {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::test_support::bb;
|
||||
use super::*;
|
||||
|
||||
fn bb(name: &str, lines: &[&str]) -> BodyBlock {
|
||||
let lines = lines
|
||||
.iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role: BlockRole::Normal,
|
||||
typed: crate::native::tir::lower_block_carrier(name, &lines, &HashMap::new())
|
||||
.map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn straddle_closure_counts_owner_arm_and_merge_tail() {
|
||||
let blocks = vec![
|
||||
|
||||
@@ -1472,20 +1472,9 @@ pub(in crate::native) fn renest_loop_exit_sibling(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::test_support::bb;
|
||||
use super::*;
|
||||
|
||||
fn bb(name: &str, lines: &[&str]) -> BodyBlock {
|
||||
let lines = lines
|
||||
.iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role: BlockRole::Normal,
|
||||
typed: tir::lower_block_carrier(name, &lines, &HashMap::new()).map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r2_straddle_derivation_is_reject_only() {
|
||||
let admitted = vec![
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//! Shared block fixtures for the structurizer's unit tests.
|
||||
//!
|
||||
//! Every `#[cfg(test)] mod` under `structured_emit` builds its CFGs from the same two constructors;
|
||||
//! they lived as six byte-equivalent private copies before this module. Keeping one copy means a new
|
||||
//! test module costs a `use super::test_support::*;` line instead of another fixture builder, and a
|
||||
//! change to how production populates a block carrier is made in one place rather than found in six.
|
||||
|
||||
use super::{BlockRole, BodyBlock};
|
||||
|
||||
/// A block whose typed carrier is lowered from `lines` exactly as production does at split time
|
||||
/// (`lower_block_carrier` is the one place block instructions are lexed), with the default
|
||||
/// [`BlockRole::Normal`] every AIR-sourced block carries.
|
||||
pub(in crate::native) fn bb(name: &str, lines: &[&str]) -> BodyBlock {
|
||||
bb_role(name, BlockRole::Normal, lines)
|
||||
}
|
||||
|
||||
/// [`bb`] with an explicit structural role, for the tests that exercise role-keyed behavior.
|
||||
pub(in crate::native) fn bb_role(name: &str, role: BlockRole, lines: &[&str]) -> BodyBlock {
|
||||
let lines: Vec<String> = lines.iter().map(|line| line.to_string()).collect();
|
||||
BodyBlock {
|
||||
name: name.to_string(),
|
||||
role,
|
||||
typed: crate::native::tir::lower_block_carrier(
|
||||
name,
|
||||
&lines,
|
||||
&std::collections::HashMap::new(),
|
||||
)
|
||||
.map(Into::into),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user