Skip to content

Commit 7b7f634

Browse files
committed
Consolidate the macros for declaring compiletest suites
1 parent 0b63477 commit 7b7f634

File tree

1 file changed

+81
-82
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+81
-82
lines changed

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

+81-82
Original file line numberDiff line numberDiff line change
@@ -1133,69 +1133,19 @@ 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+
$name:ident {
1140+
path: $path:expr,
1141+
mode: $mode:expr,
1142+
suite: $suite:expr,
1143+
default: $default:expr
1144+
$( , only_hosts: $only_hosts:expr )? // default: false
1145+
$( , compare_mode: $compare_mode:expr )? // default: None
1146+
$( , )? // optional trailing comma
1147+
}
1148+
) => {
11991149
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12001150
pub struct $name {
12011151
pub compiler: Compiler,
@@ -1205,7 +1155,12 @@ macro_rules! test_definitions {
12051155
impl Step for $name {
12061156
type Output = ();
12071157
const DEFAULT: bool = $default;
1208-
const ONLY_HOSTS: bool = $host;
1158+
const ONLY_HOSTS: bool = (const {
1159+
#[allow(unused_assignments, unused_mut)]
1160+
let mut value = false;
1161+
$( value = $only_hosts; )?
1162+
value
1163+
});
12091164

12101165
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
12111166
run.suite_path($path)
@@ -1224,15 +1179,20 @@ macro_rules! test_definitions {
12241179
mode: $mode,
12251180
suite: $suite,
12261181
path: $path,
1227-
compare_mode: $compare_mode,
1182+
compare_mode: (const {
1183+
#[allow(unused_assignments, unused_mut)]
1184+
let mut value = None;
1185+
$( value = $compare_mode; )?
1186+
value
1187+
}),
12281188
})
12291189
}
12301190
}
12311191
};
12321192
}
12331193

12341194
/// Declares an alias for running the [`Coverage`] tests in only one mode.
1235-
/// Adapted from [`test_definitions`].
1195+
/// Adapted from [`test`].
12361196
macro_rules! coverage_test_alias {
12371197
($name:ident {
12381198
alias_and_mode: $alias_and_mode:expr, // &'static str
@@ -1410,37 +1370,74 @@ impl Step for CrateBuildHelper {
14101370
}
14111371
}
14121372

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

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

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

1419-
default_test!(CodegenUnits {
1379+
test!(CodegenUnits {
14201380
path: "tests/codegen-units",
14211381
mode: "codegen-units",
1422-
suite: "codegen-units"
1382+
suite: "codegen-units",
1383+
default: true,
14231384
});
14241385

1425-
default_test!(Incremental { path: "tests/incremental", mode: "incremental", suite: "incremental" });
1386+
test!(Incremental {
1387+
path: "tests/incremental",
1388+
mode: "incremental",
1389+
suite: "incremental",
1390+
default: true,
1391+
});
14261392

1427-
default_test_with_compare_mode!(Debuginfo {
1393+
test!(Debuginfo {
14281394
path: "tests/debuginfo",
14291395
mode: "debuginfo",
14301396
suite: "debuginfo",
1431-
compare_mode: "split-dwarf"
1397+
default: true,
1398+
compare_mode: Some("split-dwarf"),
14321399
});
14331400

1434-
host_test!(UiFullDeps { path: "tests/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1401+
test!(UiFullDeps {
1402+
path: "tests/ui-fulldeps",
1403+
mode: "ui",
1404+
suite: "ui-fulldeps",
1405+
default: true,
1406+
only_hosts: true,
1407+
});
14351408

1436-
host_test!(Rustdoc { path: "tests/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1437-
host_test!(RustdocUi { path: "tests/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1409+
test!(Rustdoc {
1410+
path: "tests/rustdoc",
1411+
mode: "rustdoc",
1412+
suite: "rustdoc",
1413+
default: true,
1414+
only_hosts: true,
1415+
});
1416+
test!(RustdocUi {
1417+
path: "tests/rustdoc-ui",
1418+
mode: "ui",
1419+
suite: "rustdoc-ui",
1420+
default: true,
1421+
only_hosts: true,
1422+
});
14381423

1439-
host_test!(RustdocJson { path: "tests/rustdoc-json", mode: "rustdoc-json", suite: "rustdoc-json" });
1424+
test!(RustdocJson {
1425+
path: "tests/rustdoc-json",
1426+
mode: "rustdoc-json",
1427+
suite: "rustdoc-json",
1428+
default: true,
1429+
only_hosts: true,
1430+
});
14401431

1441-
host_test!(Pretty { path: "tests/pretty", mode: "pretty", suite: "pretty" });
1432+
test!(Pretty {
1433+
path: "tests/pretty",
1434+
mode: "pretty",
1435+
suite: "pretty",
1436+
default: true,
1437+
only_hosts: true,
1438+
});
14421439

1443-
/// Special-handling is needed for `run-make`, so don't use `default_test` for defining `RunMake`
1440+
/// Special-handling is needed for `run-make`, so don't use `test!` for defining `RunMake`
14441441
/// tests.
14451442
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
14461443
pub struct RunMake {
@@ -1475,7 +1472,7 @@ impl Step for RunMake {
14751472
}
14761473
}
14771474

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

14801477
/// Coverage tests are a bit more complicated than other test suites, because
14811478
/// we want to run the same set of test files in multiple different modes,
@@ -1569,10 +1566,12 @@ coverage_test_alias!(CoverageRun {
15691566
only_hosts: true,
15701567
});
15711568

1572-
host_test!(CoverageRunRustdoc {
1569+
test!(CoverageRunRustdoc {
15731570
path: "tests/coverage-run-rustdoc",
15741571
mode: "coverage-run",
1575-
suite: "coverage-run-rustdoc"
1572+
suite: "coverage-run-rustdoc",
1573+
default: true,
1574+
only_hosts: true,
15761575
});
15771576

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

0 commit comments

Comments
 (0)