Skip to content

Commit 006bb3c

Browse files
committed
Auto merge of rust-lang#2377 - rust-lang:only-on-host, r=oli-obk
Add test flag for running a test only on the host
2 parents 86911fd + 8527bfc commit 006bb3c

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

miri

+3-4
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ find_sysroot() {
133133
# Run command.
134134
case "$COMMAND" in
135135
install)
136-
# "--locked" to respect the Cargo.lock file if it exists,
137-
# "--offline" to avoid querying the registry (for yanked packages).
138-
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked --offline "$@"
139-
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --offline "$@"
136+
# "--locked" to respect the Cargo.lock file if it exists.
137+
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked "$@"
138+
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked "$@"
140139
;;
141140
check)
142141
# Check, and let caller control flags.

ui_test/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ their command specifies, or the test will fail without even being run.
2525

2626
* `//@ignore-XXX` avoids running the test on targets whose triple contains `XXX`
2727
* `XXX` can also be one of `64bit`, `32bit` or `16bit`
28+
* `XXX` can also be `on-host`, which will only run the test during cross compilation testing.
2829
* `//@only-XXX` avoids running the test on targets whose triple **does not** contain `XXX`
2930
* `XXX` can also be one of `64bit`, `32bit` or `16bit`
31+
* `XXX` can also be `on-host`, which will not run the test during cross compilation testing
3032
* `//@stderr-per-bitwidth` produces one stderr file per bitwidth, as they may differ significantly sometimes
3133
* `//@error-pattern: XXX` make sure the stderr output contains `XXX`
3234
* `//@revisions: XXX YYY` runs the test once for each space separated name in the list

ui_test/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn run_tests(config: Config) -> Result<()> {
109109
}
110110
let comments = Comments::parse_file(&path)?;
111111
// Ignore file if only/ignore rules do (not) apply
112-
if !test_file_conditions(&comments, &target) {
112+
if !test_file_conditions(&comments, &target, &config) {
113113
ignored.fetch_add(1, Ordering::Relaxed);
114114
eprintln!(
115115
"{} ... {}",
@@ -499,19 +499,20 @@ fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) ->
499499
path.with_extension(kind)
500500
}
501501

502-
fn test_condition(condition: &Condition, target: &str) -> bool {
502+
fn test_condition(condition: &Condition, target: &str, config: &Config) -> bool {
503503
match condition {
504504
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
505505
Condition::Target(t) => target.contains(t),
506+
Condition::OnHost => config.target.is_none(),
506507
}
507508
}
508509

509510
/// Returns whether according to the in-file conditions, this file should be run.
510-
fn test_file_conditions(comments: &Comments, target: &str) -> bool {
511-
if comments.ignore.iter().any(|c| test_condition(c, target)) {
511+
fn test_file_conditions(comments: &Comments, target: &str, config: &Config) -> bool {
512+
if comments.ignore.iter().any(|c| test_condition(c, target, config)) {
512513
return false;
513514
}
514-
comments.only.iter().all(|c| test_condition(c, target))
515+
comments.only.iter().all(|c| test_condition(c, target, config))
515516
}
516517

517518
// Taken 1:1 from compiletest-rs

ui_test/src/parser.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub(crate) enum Condition {
4343
Target(String),
4444
/// Tests that the bitwidth is the given one.
4545
Bitwidth(u8),
46+
/// Tests that the target is the host.
47+
OnHost,
4648
}
4749

4850
#[derive(Debug, Clone)]
@@ -64,7 +66,9 @@ pub(crate) struct ErrorMatch {
6466

6567
impl Condition {
6668
fn parse(c: &str) -> Self {
67-
if let Some(bits) = c.strip_suffix("bit") {
69+
if c == "on-host" {
70+
Condition::OnHost
71+
} else if let Some(bits) = c.strip_suffix("bit") {
6872
let bits: u8 = bits.parse().expect(
6973
"ignore/only filter ending in 'bit' must be of the form 'Nbit' for some integer N",
7074
);

0 commit comments

Comments
 (0)