Skip to content

Commit 65c698e

Browse files
authored
Rollup merge of #134876 - Zalathar:bootstrap-test-macros, r=jieyouxu
bootstrap: Consolidate the macros for declaring compiletest test suites Instead of using a dizzying assortment of different macros to declare these test suite steps, we can mostly just use one `test!` macro with a few optional named arguments. I'm pretty sure that this doesn't change any behaviour, but please do double-check each of the individual declarations.
2 parents 7768c39 + 1e37bbe commit 65c698e

File tree

1 file changed

+113
-103
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+113
-103
lines changed

src/bootstrap/src/core/build_steps/test.rs

+113-103
Original file line numberDiff line numberDiff line change
@@ -1133,69 +1133,21 @@ fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
11331133
builder.out.join(host).join("test")
11341134
}
11351135

1136-
macro_rules! default_test {
1137-
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1138-
test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1139-
};
1140-
}
1141-
1142-
macro_rules! default_test_with_compare_mode {
1143-
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1144-
compare_mode: $compare_mode:expr }) => {
1145-
test_with_compare_mode!($name {
1146-
path: $path,
1147-
mode: $mode,
1148-
suite: $suite,
1149-
default: true,
1150-
host: false,
1151-
compare_mode: $compare_mode
1152-
});
1153-
};
1154-
}
1155-
1156-
macro_rules! host_test {
1157-
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1158-
test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1159-
};
1160-
}
1161-
1136+
/// Declares a test step that invokes compiletest on a particular test suite.
11621137
macro_rules! test {
1163-
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1164-
host: $host:expr }) => {
1165-
test_definitions!($name {
1166-
path: $path,
1167-
mode: $mode,
1168-
suite: $suite,
1169-
default: $default,
1170-
host: $host,
1171-
compare_mode: None
1172-
});
1173-
};
1174-
}
1175-
1176-
macro_rules! test_with_compare_mode {
1177-
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1178-
host: $host:expr, compare_mode: $compare_mode:expr }) => {
1179-
test_definitions!($name {
1180-
path: $path,
1181-
mode: $mode,
1182-
suite: $suite,
1183-
default: $default,
1184-
host: $host,
1185-
compare_mode: Some($compare_mode)
1186-
});
1187-
};
1188-
}
1189-
1190-
macro_rules! test_definitions {
1191-
($name:ident {
1192-
path: $path:expr,
1193-
mode: $mode:expr,
1194-
suite: $suite:expr,
1195-
default: $default:expr,
1196-
host: $host:expr,
1197-
compare_mode: $compare_mode:expr
1198-
}) => {
1138+
(
1139+
$( #[$attr:meta] )* // allow docstrings and attributes
1140+
$name:ident {
1141+
path: $path:expr,
1142+
mode: $mode:expr,
1143+
suite: $suite:expr,
1144+
default: $default:expr
1145+
$( , only_hosts: $only_hosts:expr )? // default: false
1146+
$( , compare_mode: $compare_mode:expr )? // default: None
1147+
$( , )? // optional trailing comma
1148+
}
1149+
) => {
1150+
$( #[$attr] )*
11991151
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12001152
pub struct $name {
12011153
pub compiler: Compiler,
@@ -1205,7 +1157,12 @@ macro_rules! test_definitions {
12051157
impl Step for $name {
12061158
type Output = ();
12071159
const DEFAULT: bool = $default;
1208-
const ONLY_HOSTS: bool = $host;
1160+
const ONLY_HOSTS: bool = (const {
1161+
#[allow(unused_assignments, unused_mut)]
1162+
let mut value = false;
1163+
$( value = $only_hosts; )?
1164+
value
1165+
});
12091166

12101167
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
12111168
run.suite_path($path)
@@ -1224,21 +1181,31 @@ macro_rules! test_definitions {
12241181
mode: $mode,
12251182
suite: $suite,
12261183
path: $path,
1227-
compare_mode: $compare_mode,
1184+
compare_mode: (const {
1185+
#[allow(unused_assignments, unused_mut)]
1186+
let mut value = None;
1187+
$( value = $compare_mode; )?
1188+
value
1189+
}),
12281190
})
12291191
}
12301192
}
12311193
};
12321194
}
12331195

12341196
/// Declares an alias for running the [`Coverage`] tests in only one mode.
1235-
/// Adapted from [`test_definitions`].
1197+
/// Adapted from [`test`].
12361198
macro_rules! coverage_test_alias {
1237-
($name:ident {
1238-
alias_and_mode: $alias_and_mode:expr, // &'static str
1239-
default: $default:expr, // bool
1240-
only_hosts: $only_hosts:expr $(,)? // bool
1241-
}) => {
1199+
(
1200+
$( #[$attr:meta] )* // allow docstrings and attributes
1201+
$name:ident {
1202+
alias_and_mode: $alias_and_mode:expr, // &'static str
1203+
default: $default:expr, // bool
1204+
only_hosts: $only_hosts:expr // bool
1205+
$( , )? // optional trailing comma
1206+
}
1207+
) => {
1208+
$( #[$attr] )*
12421209
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12431210
pub struct $name {
12441211
pub compiler: Compiler,
@@ -1410,37 +1377,74 @@ impl Step for CrateBuildHelper {
14101377
}
14111378
}
14121379

1413-
default_test!(Ui { path: "tests/ui", mode: "ui", suite: "ui" });
1380+
test!(Ui { path: "tests/ui", mode: "ui", suite: "ui", default: true });
14141381

1415-
default_test!(Crashes { path: "tests/crashes", mode: "crashes", suite: "crashes" });
1382+
test!(Crashes { path: "tests/crashes", mode: "crashes", suite: "crashes", default: true });
14161383

1417-
default_test!(Codegen { path: "tests/codegen", mode: "codegen", suite: "codegen" });
1384+
test!(Codegen { path: "tests/codegen", mode: "codegen", suite: "codegen", default: true });
14181385

1419-
default_test!(CodegenUnits {
1386+
test!(CodegenUnits {
14201387
path: "tests/codegen-units",
14211388
mode: "codegen-units",
1422-
suite: "codegen-units"
1389+
suite: "codegen-units",
1390+
default: true,
14231391
});
14241392

1425-
default_test!(Incremental { path: "tests/incremental", mode: "incremental", suite: "incremental" });
1393+
test!(Incremental {
1394+
path: "tests/incremental",
1395+
mode: "incremental",
1396+
suite: "incremental",
1397+
default: true,
1398+
});
14261399

1427-
default_test_with_compare_mode!(Debuginfo {
1400+
test!(Debuginfo {
14281401
path: "tests/debuginfo",
14291402
mode: "debuginfo",
14301403
suite: "debuginfo",
1431-
compare_mode: "split-dwarf"
1404+
default: true,
1405+
compare_mode: Some("split-dwarf"),
14321406
});
14331407

1434-
host_test!(UiFullDeps { path: "tests/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1408+
test!(UiFullDeps {
1409+
path: "tests/ui-fulldeps",
1410+
mode: "ui",
1411+
suite: "ui-fulldeps",
1412+
default: true,
1413+
only_hosts: true,
1414+
});
14351415

1436-
host_test!(Rustdoc { path: "tests/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1437-
host_test!(RustdocUi { path: "tests/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1416+
test!(Rustdoc {
1417+
path: "tests/rustdoc",
1418+
mode: "rustdoc",
1419+
suite: "rustdoc",
1420+
default: true,
1421+
only_hosts: true,
1422+
});
1423+
test!(RustdocUi {
1424+
path: "tests/rustdoc-ui",
1425+
mode: "ui",
1426+
suite: "rustdoc-ui",
1427+
default: true,
1428+
only_hosts: true,
1429+
});
14381430

1439-
host_test!(RustdocJson { path: "tests/rustdoc-json", mode: "rustdoc-json", suite: "rustdoc-json" });
1431+
test!(RustdocJson {
1432+
path: "tests/rustdoc-json",
1433+
mode: "rustdoc-json",
1434+
suite: "rustdoc-json",
1435+
default: true,
1436+
only_hosts: true,
1437+
});
14401438

1441-
host_test!(Pretty { path: "tests/pretty", mode: "pretty", suite: "pretty" });
1439+
test!(Pretty {
1440+
path: "tests/pretty",
1441+
mode: "pretty",
1442+
suite: "pretty",
1443+
default: true,
1444+
only_hosts: true,
1445+
});
14421446

1443-
/// Special-handling is needed for `run-make`, so don't use `default_test` for defining `RunMake`
1447+
/// Special-handling is needed for `run-make`, so don't use `test!` for defining `RunMake`
14441448
/// tests.
14451449
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
14461450
pub struct RunMake {
@@ -1475,7 +1479,7 @@ impl Step for RunMake {
14751479
}
14761480
}
14771481

1478-
default_test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly" });
1482+
test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly", default: true });
14791483

14801484
/// Coverage tests are a bit more complicated than other test suites, because
14811485
/// we want to run the same set of test files in multiple different modes,
@@ -1552,27 +1556,33 @@ impl Step for Coverage {
15521556
}
15531557
}
15541558

1555-
// Runs `tests/coverage` in "coverage-map" mode only.
1556-
// Used by `x test` and `x test coverage-map`.
1557-
coverage_test_alias!(CoverageMap {
1558-
alias_and_mode: "coverage-map",
1559-
default: true,
1560-
only_hosts: false,
1561-
});
1562-
// Runs `tests/coverage` in "coverage-run" mode only.
1563-
// Used by `x test` and `x test coverage-run`.
1564-
coverage_test_alias!(CoverageRun {
1565-
alias_and_mode: "coverage-run",
1566-
default: true,
1567-
// Compiletest knows how to automatically skip these tests when cross-compiling,
1568-
// but skipping the whole step here makes it clearer that they haven't run at all.
1569-
only_hosts: true,
1570-
});
1559+
coverage_test_alias! {
1560+
/// Runs the `tests/coverage` test suite in "coverage-map" mode only.
1561+
/// Used by `x test` and `x test coverage-map`.
1562+
CoverageMap {
1563+
alias_and_mode: "coverage-map",
1564+
default: true,
1565+
only_hosts: false,
1566+
}
1567+
}
1568+
coverage_test_alias! {
1569+
/// Runs the `tests/coverage` test suite in "coverage-run" mode only.
1570+
/// Used by `x test` and `x test coverage-run`.
1571+
CoverageRun {
1572+
alias_and_mode: "coverage-run",
1573+
default: true,
1574+
// Compiletest knows how to automatically skip these tests when cross-compiling,
1575+
// but skipping the whole step here makes it clearer that they haven't run at all.
1576+
only_hosts: true,
1577+
}
1578+
}
15711579

1572-
host_test!(CoverageRunRustdoc {
1580+
test!(CoverageRunRustdoc {
15731581
path: "tests/coverage-run-rustdoc",
15741582
mode: "coverage-run",
1575-
suite: "coverage-run-rustdoc"
1583+
suite: "coverage-run-rustdoc",
1584+
default: true,
1585+
only_hosts: true,
15761586
});
15771587

15781588
// For the mir-opt suite we do not use macros, as we need custom behavior when blessing.

0 commit comments

Comments
 (0)