Skip to content

Commit 444841b

Browse files
committed
Add test flag for running a test only on the host
1 parent 43100f5 commit 444841b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

ui_test/README.md

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 6 additions & 0 deletions
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,6 +66,10 @@ pub(crate) struct ErrorMatch {
6466

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

0 commit comments

Comments
 (0)