Skip to content

Commit f06625f

Browse files
committed
Move test_condition from a free function to a Config method
1 parent 2a6a4fd commit f06625f

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/config.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use regex::bytes::Regex;
22
use spanned::{Span, Spanned};
33

44
use crate::{
5-
dependencies::build_dependencies, filter::Match, per_test_config::Comments, CommandBuilder,
6-
Mode, RustfixMode,
5+
dependencies::build_dependencies,
6+
filter::Match,
7+
per_test_config::{Comments, Condition},
8+
CommandBuilder, Mode, RustfixMode,
79
};
810
pub use color_eyre;
911
use color_eyre::eyre::Result;
@@ -274,6 +276,16 @@ impl Config {
274276
.iter()
275277
.any(|arch| self.target.as_ref().unwrap().contains(arch))
276278
}
279+
280+
pub(crate) fn test_condition(&self, condition: &Condition) -> bool {
281+
let target = self.target.as_ref().unwrap();
282+
match condition {
283+
Condition::Bitwidth(bits) => crate::get_pointer_width(target) == *bits,
284+
Condition::Target(t) => target.contains(t),
285+
Condition::Host(t) => self.host.as_ref().unwrap().contains(t),
286+
Condition::OnHost => self.host_matches(target),
287+
}
288+
}
277289
}
278290

279291
#[derive(Debug, Clone)]

src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::process::{Command, ExitStatus, Output};
2525
use std::thread;
2626
use test_result::{Errored, TestOk, TestResult, TestRun};
2727

28-
use crate::parser::{Comments, Condition};
28+
use crate::parser::Comments;
2929

3030
mod cmd;
3131
mod config;
@@ -1211,24 +1211,14 @@ fn output_path(
12111211
path.with_extension(kind)
12121212
}
12131213

1214-
fn test_condition(condition: &Condition, config: &Config) -> bool {
1215-
let target = config.target.as_ref().unwrap();
1216-
match condition {
1217-
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
1218-
Condition::Target(t) => target.contains(t),
1219-
Condition::Host(t) => config.host.as_ref().unwrap().contains(t),
1220-
Condition::OnHost => config.host_matches(target),
1221-
}
1222-
}
1223-
12241214
impl dyn TestStatus {
12251215
/// Returns whether according to the in-file conditions, this file should be run.
12261216
fn test_file_conditions(&self, comments: &Comments, config: &Config) -> bool {
12271217
let revision = self.revision();
12281218
if comments
12291219
.for_revision(revision)
12301220
.flat_map(|r| r.ignore.iter())
1231-
.any(|c| test_condition(c, config))
1221+
.any(|c| config.test_condition(c))
12321222
{
12331223
return config.run_only_ignored;
12341224
}
@@ -1241,7 +1231,7 @@ impl dyn TestStatus {
12411231
comments
12421232
.for_revision(revision)
12431233
.flat_map(|r| r.only.iter())
1244-
.all(|c| test_condition(c, config))
1234+
.all(|c| config.test_condition(c))
12451235
^ config.run_only_ignored
12461236
}
12471237
}

0 commit comments

Comments
 (0)