Skip to content

Commit 6b17c94

Browse files
authored
Merge pull request #161 from oli-obk/nextest
Nextest
2 parents 0c53646 + 3b9f79c commit 6b17c94

File tree

5 files changed

+99
-20
lines changed

5 files changed

+99
-20
lines changed

src/config.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
};
1111

1212
mod args;
13-
pub use args::Args;
13+
pub use args::{Args, Format};
1414

1515
#[derive(Debug, Clone)]
1616
/// Central datastructure containing all information to run the tests.
@@ -53,6 +53,12 @@ pub struct Config {
5353
pub filter_files: Vec<String>,
5454
/// Override the number of threads to use.
5555
pub threads: Option<NonZeroUsize>,
56+
/// Nextest emulation: only list the test itself, not its components.
57+
pub list: bool,
58+
/// Only run the tests that are ignored.
59+
pub run_only_ignored: bool,
60+
/// Filters must match exactly instead of just checking for substrings.
61+
pub filter_exact: bool,
5662
}
5763

5864
impl Config {
@@ -94,6 +100,9 @@ impl Config {
94100
skip_files: Vec::new(),
95101
filter_files: Vec::new(),
96102
threads: None,
103+
list: false,
104+
run_only_ignored: false,
105+
filter_exact: false,
97106
}
98107
}
99108

@@ -119,9 +128,12 @@ impl Config {
119128
pub fn with_args(&mut self, args: &Args, default_bless: bool) {
120129
let Args {
121130
ref filters,
122-
quiet: _,
123131
check,
124132
bless,
133+
list,
134+
exact,
135+
ignored,
136+
format: _,
125137
threads,
126138
ref skip,
127139
} = *args;
@@ -130,6 +142,10 @@ impl Config {
130142

131143
self.filter_files.extend_from_slice(filters);
132144
self.skip_files.extend_from_slice(skip);
145+
self.run_only_ignored = ignored;
146+
self.filter_exact = exact;
147+
148+
self.list = list;
133149

134150
let bless = match (bless, check) {
135151
(_, true) => false,

src/config/args.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ pub struct Args {
1111
/// Filters that will be used to match on individual tests
1212
pub filters: Vec<String>,
1313

14-
/// Whether to minimize output given to the user.
15-
pub quiet: bool,
16-
1714
/// Whether to error on mismatches between `.stderr` files and actual
1815
/// output.
1916
pub check: bool,
@@ -22,13 +19,35 @@ pub struct Args {
2219
/// output.
2320
pub bless: bool,
2421

22+
/// Only run the test matching the filters exactly.
23+
pub exact: bool,
24+
25+
/// Whether to only run ignored tests.
26+
pub ignored: bool,
27+
28+
/// List the tests that can be run.
29+
pub list: bool,
30+
31+
/// Choose an output format
32+
pub format: Format,
33+
2534
/// The number of threads to use
2635
pub threads: Option<NonZeroUsize>,
2736

2837
/// Skip tests whose names contain any of these entries.
2938
pub skip: Vec<String>,
3039
}
3140

41+
/// Possible choices for styling the output.
42+
#[derive(Debug, Copy, Clone, Default)]
43+
pub enum Format {
44+
/// Print one line per test
45+
#[default]
46+
Pretty,
47+
/// Remove test lines once the test finishes and show a progress bar.
48+
Terse,
49+
}
50+
3251
impl Args {
3352
/// Parse the program arguments.
3453
/// This is meant to be used if `ui_test` is used as a `harness=false` test, called from `cargo test`.
@@ -43,11 +62,25 @@ impl Args {
4362
continue;
4463
}
4564
if arg == "--quiet" {
46-
self.quiet = true;
65+
self.format = Format::Terse;
4766
} else if arg == "--check" {
4867
self.check = true;
4968
} else if arg == "--bless" {
5069
self.bless = true;
70+
} else if arg == "--list" {
71+
self.list = true;
72+
} else if arg == "--exact" {
73+
self.exact = true;
74+
} else if arg == "--ignored" {
75+
self.ignored = true;
76+
} else if arg == "--nocapture" {
77+
// We ignore this flag for now.
78+
} else if let Some(format) = parse_value("--format", &arg, &mut iter)? {
79+
self.format = match &*format {
80+
"terse" => Format::Terse,
81+
"pretty" => Format::Pretty,
82+
_ => bail!("unsupported format `{format}`"),
83+
};
5184
} else if let Some(skip) = parse_value("--skip", &arg, &mut iter)? {
5285
self.skip.push(skip.into_owned());
5386
} else if arg == "--help" {

src/lib.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,15 @@ pub type Filter = Vec<(Match, &'static [u8])>;
116116
/// Will additionally process command line arguments.
117117
pub fn run_tests(mut config: Config) -> Result<()> {
118118
let args = Args::test()?;
119-
if !args.quiet {
119+
if let Format::Pretty = args.format {
120120
println!("Compiler: {}", config.program.display());
121121
}
122122

123123
let name = config.root_dir.display().to_string();
124124

125-
let text = if args.quiet {
126-
status_emitter::Text::quiet()
127-
} else {
128-
status_emitter::Text::verbose()
125+
let text = match args.format {
126+
Format::Terse => status_emitter::Text::quiet(),
127+
Format::Pretty => status_emitter::Text::verbose(),
129128
};
130129
config.with_args(&args, true);
131130

@@ -149,7 +148,15 @@ pub fn default_file_filter(path: &Path, config: &Config) -> bool {
149148
/// To only include rust files see [`default_file_filter`].
150149
pub fn default_any_file_filter(path: &Path, config: &Config) -> bool {
151150
let path = path.display().to_string();
152-
let contains_path = |files: &[String]| files.iter().any(|f| path.contains(f));
151+
let contains_path = |files: &[String]| {
152+
files.iter().any(|f| {
153+
if config.filter_exact {
154+
*f == path
155+
} else {
156+
path.contains(f)
157+
}
158+
})
159+
};
153160

154161
if contains_path(&config.skip_files) {
155162
return false;
@@ -229,6 +236,23 @@ pub fn run_tests_generic(
229236
per_file_config: impl Fn(&mut Config, &Path, &[u8]) + Sync,
230237
status_emitter: impl StatusEmitter + Send,
231238
) -> Result<()> {
239+
// Nexttest emulation: we act as if we are one single test.
240+
if configs.iter().any(|c| c.list) {
241+
if configs.iter().any(|c| !c.run_only_ignored) {
242+
println!("ui_test: test");
243+
}
244+
return Ok(());
245+
}
246+
for config in &mut configs {
247+
if config.filter_exact
248+
&& config.filter_files.len() == 1
249+
&& config.filter_files[0] == "ui_test"
250+
{
251+
config.filter_exact = false;
252+
config.filter_files.clear();
253+
}
254+
}
255+
232256
for config in &mut configs {
233257
config.fill_host_and_target()?;
234258
}
@@ -1188,18 +1212,19 @@ impl dyn TestStatus {
11881212
.flat_map(|r| r.ignore.iter())
11891213
.any(|c| test_condition(c, config))
11901214
{
1191-
return false;
1215+
return config.run_only_ignored;
11921216
}
11931217
if comments
11941218
.for_revision(revision)
11951219
.any(|r| r.needs_asm_support && !config.has_asm_support())
11961220
{
1197-
return false;
1221+
return config.run_only_ignored;
11981222
}
11991223
comments
12001224
.for_revision(revision)
12011225
.flat_map(|r| r.only.iter())
12021226
.all(|c| test_condition(c, config))
1227+
^ config.run_only_ignored
12031228
}
12041229
}
12051230

src/status_emitter.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
github_actions,
1414
parser::Pattern,
1515
rustc_stderr::{Message, Span},
16-
Error, Errored, Errors, TestOk, TestResult,
16+
Error, Errored, Errors, Format, TestOk, TestResult,
1717
};
1818
use std::{
1919
collections::HashMap,
@@ -184,6 +184,15 @@ impl Text {
184184
}
185185
}
186186

187+
impl From<Format> for Text {
188+
fn from(format: Format) -> Self {
189+
match format {
190+
Format::Terse => Text::quiet(),
191+
Format::Pretty => Text::verbose(),
192+
}
193+
}
194+
}
195+
187196
struct TextTest {
188197
text: Text,
189198
path: PathBuf,

tests/integration.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ fn main() -> Result<()> {
7070
config.filter("program not found", "No such file or directory");
7171
config.filter(" \\(os error [0-9]+\\)", "");
7272

73-
let text = if args.quiet {
74-
ui_test::status_emitter::Text::quiet()
75-
} else {
76-
ui_test::status_emitter::Text::verbose()
77-
};
73+
let text = ui_test::status_emitter::Text::from(args.format);
7874

7975
run_tests_generic(
8076
vec![

0 commit comments

Comments
 (0)