Skip to content

Commit 2834fae

Browse files
committed
# This is a combination of 2 commits.
# This is the 1st commit message: remove tests after they pass # This is the commit message #2: fixes for CI
1 parent 7047704 commit 2834fae

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

src/bootstrap/failed.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@ use std::{
77

88
use crate::builder::Builder;
99

10+
use clap::Parser;
11+
1012
pub const TRACKER_FILE: &'static str = "./src/bootstrap/test.tracker";
1113

1214
/// Runs all the tests that failed on their last run
13-
pub fn failed(_builder: &Builder<'_>) {
14-
let _failed_tests = get_failed_tests();
15+
pub fn failed(builder: &Builder<'_>) {
16+
let mut build: crate::Build = builder.build.clone();
17+
let failed_tests = get_failed_tests();
18+
19+
if failed_tests.is_empty() {
20+
println!("No tests failed on the previous iteration!");
21+
return;
22+
}
23+
24+
build.config.paths = failed_tests;
25+
build.config.cmd = crate::flags::Flags::parse_from(["x.py", "test", "--force-rerun"]).cmd;
26+
27+
build.build();
1528
}
1629

1730
/// Returns a list of paths of tests that failed the last time that they were run
1831
fn get_failed_tests() -> Vec<PathBuf> {
1932
let contents = {
2033
let path = Path::new(TRACKER_FILE);
2134
let mut f = File::open(path).unwrap_or_else(|_| {
22-
eprintln!("Please run `x.py test` atleast once before running this command");
35+
eprintln!("Please run `x.py test` atleast once before running this command.");
2336
panic!();
2437
});
2538

@@ -32,10 +45,15 @@ fn get_failed_tests() -> Vec<PathBuf> {
3245
let failed_tests =
3346
serde_json::from_str::<HashSet<&str>>(&contents).expect("failed to deserialise tracker");
3447

35-
for test in failed_tests {
36-
let test = test.split(" ").collect::<Vec<_>>();
37-
println!("{:?}", test);
38-
}
39-
40-
vec![]
48+
failed_tests
49+
.iter()
50+
.map(|test| {
51+
test.split(" ")
52+
.filter(|x| {
53+
let mut chars = x.chars();
54+
!matches!(chars.nth(0).unwrap(), '[' if matches!(chars.last().unwrap(), ']'))
55+
})
56+
.collect::<PathBuf>()
57+
})
58+
.collect::<Vec<_>>()
4159
}

src/bootstrap/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ pub struct Build {
218218
in_tree_llvm_info: channel::GitInfo,
219219
local_rebuild: bool,
220220
fail_fast: bool,
221-
failed: bool,
222221
doc_tests: DocTests,
223222
verbosity: usize,
224223

@@ -439,7 +438,6 @@ impl Build {
439438
initial_libdir,
440439
initial_sysroot: initial_sysroot.into(),
441440
local_rebuild: config.local_rebuild,
442-
failed: config.cmd.failed(),
443441
fail_fast: config.cmd.fail_fast(),
444442
doc_tests: config.cmd.doc_tests(),
445443
verbosity: config.verbose,

src/bootstrap/render_tests.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::failed::TRACKER_FILE;
1717
use termcolor::{Color, ColorSpec, WriteColor};
1818

1919
const TERSE_TESTS_PER_LINE: usize = 88;
20-
#[allow(unused)] // FIXME unused warning even though it is
2120

2221
pub(crate) fn add_flags_and_try_run_tests(builder: &Builder<'_>, cmd: &mut Command) -> bool {
2322
if cmd.get_args().position(|arg| arg == "--").is_none() {
@@ -283,6 +282,7 @@ impl<'a> Renderer<'a> {
283282
}
284283
Message::Test(TestMessage::Ok(outcome)) => {
285284
self.render_test_outcome(Outcome::Ok, &outcome);
285+
self.remove_failure(&outcome.name);
286286
}
287287
Message::Test(TestMessage::Ignored(outcome)) => {
288288
self.render_test_outcome(
@@ -307,7 +307,7 @@ impl<'a> Renderer<'a> {
307307
let mut contents = String::new();
308308
{
309309
let mut file =
310-
OpenOptions::new().create(true).read(true).write(true).open(TRACKER_FILE).unwrap();
310+
OpenOptions::new().read(true).write(true).create(true).open(TRACKER_FILE).unwrap();
311311
file.read_to_string(&mut contents).unwrap();
312312
}
313313

@@ -317,14 +317,20 @@ impl<'a> Renderer<'a> {
317317
}
318318

319319
/// Add a test that failed to the list
320-
#[inline]
321320
fn track_failure(&mut self, name: &str) {
322321
self.tracker.insert(String::from(name));
323322
}
324323

324+
/// Remove a test that no longer fails from the list
325+
fn remove_failure(&mut self, name: &str) {
326+
if self.tracker.contains(name) {
327+
self.tracker.remove(name);
328+
}
329+
}
330+
325331
/// Store the state of the tracker into file for retrieval on next run
326332
fn end_tracking(&mut self) {
327-
let mut file = OpenOptions::new().write(true).open(TRACKER_FILE).unwrap();
333+
let mut file = OpenOptions::new().write(true).truncate(true).open(TRACKER_FILE).unwrap();
328334
file.write_all(serde_json::to_string(&self.tracker).unwrap().as_bytes())
329335
.expect("failed to write to tracking file");
330336
}

src/bootstrap/suggest.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
5858

5959
if run {
6060
for sug in suggestions {
61-
println!("paths: {:?}", &sug.2);
6261
let mut build: crate::Build = builder.build.clone();
6362
build.config.paths = sug.2;
6463
build.config.cmd = crate::flags::Flags::parse_from(["x.py", sug.0]).cmd;

src/etc/completions/x.py.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ _x.py() {
16251625
return 0
16261626
;;
16271627
x.py__test)
1628-
opts="-v -i -j -h --no-fail-fast --skip --test-args --rustc-args --no-doc --failed --doc --bless --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --verbose --incremental --config --build-dir --build --host --target --exclude --include-default-paths --rustc-error-format --on-fail --dry-run --stage --keep-stage --keep-stage-std --src --jobs --warnings --error-format --json-output --color --llvm-skip-rebuild --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --reproducible-artifact --set --help [PATHS]... [ARGS]..."
1628+
opts="-v -i -j -h --no-fail-fast --skip --test-args --rustc-args --no-doc --failed --doc --bless --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --verbose --incremental --config --build-dir --build --host --target --exclude --include-default-paths --rustc-error-format --on-fail --dry-run --stage --keep-stage --keep-stage-std --src --jobs --warnings --error-format --json-output --color --llvm-skip-rebuild --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --reproducible-artifact --set --help [PATHS]... [ARGS]..."
16291629
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
16301630
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
16311631
return 0

0 commit comments

Comments
 (0)