Skip to content

Commit b46620d

Browse files
committed
Remove Tee, since it turned out to not be very useful
1 parent 6f762f5 commit b46620d

File tree

6 files changed

+49
-84
lines changed

6 files changed

+49
-84
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ build/
5353
# Created by default with `src/ci/docker/run.sh`
5454
/obj/
5555
/rustc-ice*
56-
/parse-float*
5756

5857
## Temporary files
5958
*~

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,7 +3534,6 @@ impl Step for TestFloatParse {
35343534
cargo_run.arg("--");
35353535
if builder.config.args().is_empty() {
35363536
// By default, exclude tests that take longer than ~1m.
3537-
builder.info("only running a subset of tests by default");
35383537
cargo_run.arg("--skip-huge");
35393538
} else {
35403539
cargo_run.args(builder.config.args());

src/etc/test-float-parse/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ parallel, and their tests get chunked and run in parallel.
4343
There is a simple command line that allows filtering which tests are run,
4444
setting the number of iterations for fuzzing tests, limiting failures, setting
4545
timeouts, etc. See `main.rs` or run with `--help` for options.
46+
47+
Note that when running via `./x`, only tests that take less than a few minutes
48+
are run by default. Pass `-- --all` to actually run them all locally.

src/etc/test-float-parse/src/lib.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use rand::distributions::{Distribution, Standard};
1515
use rayon::prelude::*;
1616
use time::{Duration, Instant};
1717
use traits::{Float, Generator, Int};
18-
pub use ui::create_log_file;
19-
use ui::Tee;
2018

2119
/// Test generators.
2220
mod gen {
@@ -86,20 +84,13 @@ pub fn run(cfg: Config, include: &[String], exclude: &[String]) -> ExitCode {
8684
tests.retain(|test| include.iter().any(|inc| test.matches(inc)));
8785
}
8886

89-
let (logfile, logfile_name) = create_log_file();
90-
let mut out = Tee { f: &logfile };
91-
9287
for exc in initial_tests.iter().filter(|orig_name| !tests.iter().any(|t| t.name == **orig_name))
9388
{
94-
out.write_sout(format!("Skipping test '{exc}'"));
89+
println!("Skipping test '{exc}'");
9590
}
9691

97-
let elapsed = launch_tests(&mut tests, &cfg, &mut out);
98-
let ret = ui::finish(&tests, elapsed, &cfg, &mut out);
99-
100-
println!("wrote results to {logfile_name}");
101-
102-
ret
92+
let elapsed = launch_tests(&mut tests, &cfg);
93+
ui::finish(&tests, elapsed, &cfg)
10394
}
10495

10596
/// Enumerate tests to run but don't actaully run them.
@@ -191,15 +182,20 @@ impl TestInfo {
191182
v.push(info);
192183
}
193184

185+
/// Pad the short name to a common width for progress bar use.
186+
fn short_name_padded(&self) -> String {
187+
format!("{:18}", self.short_name)
188+
}
189+
194190
/// Create a progress bar for this test within a multiprogress bar.
195191
fn register_pb(&mut self, mp: &MultiProgress, drop_bars: &mut Vec<ProgressBar>) {
196-
self.pb = Some(ui::create_pb(mp, self.total_tests, &self.short_name, drop_bars));
192+
self.pb = Some(ui::create_pb(mp, self.total_tests, &self.short_name_padded(), drop_bars));
197193
}
198194

199195
/// When the test is finished, update progress bar messages and finalize.
200196
fn finalize_pb(&self, c: &Completed) {
201197
let pb = self.pb.as_ref().unwrap();
202-
ui::finalize_pb(pb, &self.short_name, c);
198+
ui::finalize_pb(pb, &self.short_name_padded(), c);
203199
}
204200

205201
/// True if this should be run after all others.
@@ -228,20 +224,21 @@ impl Msg {
228224
}
229225

230226
/// Update UI as needed for a single message received from the test runners.
231-
fn handle(self, tests: &[TestInfo], out: &mut Tee<'_>, mp: &MultiProgress) {
227+
fn handle(self, tests: &[TestInfo], mp: &MultiProgress) {
232228
let test = self.find_test(tests);
233229
let pb = test.pb.as_ref().unwrap();
234230

235231
match self.update {
236232
Update::Started => {
237-
out.write_mp(mp, format!("Testing '{}'", test.name));
233+
mp.println(format!("Testing '{}'", test.name)).unwrap();
238234
}
239235
Update::Progress { executed, failures } => {
240236
pb.set_message(format! {"{failures}"});
241237
pb.set_position(executed);
242238
}
243239
Update::Failure { fail, input } => {
244-
out.write_mp(mp, format!("Failure in '{}': {fail}. parsing '{input}'", test.name,));
240+
mp.println(format!("Failure in '{}': {fail}. parsing '{input}'", test.name))
241+
.unwrap();
245242
}
246243
Update::Completed(c) => {
247244
test.finalize_pb(&c);
@@ -252,13 +249,11 @@ impl Msg {
252249
Err(EarlyExit::MaxFailures) => "Max failures reached for",
253250
};
254251

255-
out.write_mp(
256-
mp,
257-
format!(
258-
"{prefix} generator '{}' in {:?}. {} tests run, {} failures",
259-
test.name, c.elapsed, c.executed, c.failures
260-
),
261-
);
252+
mp.println(format!(
253+
"{prefix} generator '{}' in {:?}. {} tests run, {} failures",
254+
test.name, c.elapsed, c.executed, c.failures
255+
))
256+
.unwrap();
262257
test.completed.set(c).unwrap();
263258
}
264259
};
@@ -361,12 +356,12 @@ enum EarlyExit {
361356
///
362357
/// This launches a main thread that receives messages and handlees UI updates, and uses the
363358
/// rest of the thread pool to execute the tests.
364-
fn launch_tests(tests: &mut [TestInfo], cfg: &Config, out: &mut Tee<'_>) -> Duration {
359+
fn launch_tests(tests: &mut [TestInfo], cfg: &Config) -> Duration {
365360
// Run shorter tests first
366361
tests.sort_unstable_by_key(|test| test.total_tests);
367362

368363
for test in tests.iter() {
369-
out.write_sout(format!("Launching test '{}'", test.name));
364+
println!("Launching test '{}'", test.name);
370365
}
371366

372367
// Configure progress bars
@@ -393,7 +388,7 @@ fn launch_tests(tests: &mut [TestInfo], cfg: &Config, out: &mut Tee<'_>) -> Dura
393388
}
394389

395390
let msg = rx.recv().unwrap();
396-
msg.handle(tests, out, &mp);
391+
msg.handle(tests, &mp);
397392
}
398393

399394
// All tests completed; finish things up

src/etc/test-float-parse/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Args:
2525
if fuzz tests are enabled. Pass `--fuzz-count none`
2626
to remove this limit.
2727
--skip-huge Skip tests that run for a long time.
28+
--all Reset previous `--exclude`, `--skip-huge`, and
29+
`INCLUDE` arguments (useful for running all tests
30+
via `./x`).
2831
"#;
2932

3033
enum ArgMode {
@@ -87,6 +90,12 @@ fn parse_args(args: Vec<String>) -> (tfp::Config, Vec<String>, Vec<String>) {
8790
cfg.skip_huge = true;
8891
ArgMode::Any
8992
}
93+
ArgMode::Any if arg == "--all" => {
94+
cfg.skip_huge = false;
95+
include.clear();
96+
exclude.clear();
97+
ArgMode::Any
98+
}
9099
ArgMode::Any if arg.starts_with('-') => {
91100
panic!("Unknown argument {arg}. Usage:\n{HELP}")
92101
}

src/etc/test-float-parse/src/ui.rs

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Progress bars and such.
22
3-
use std::fs;
43
use std::io::{self, Write};
54
use std::process::ExitCode;
6-
use std::time::{Duration, SystemTime};
5+
use std::time::Duration;
76

87
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
98

@@ -18,12 +17,11 @@ const PB_TEMPLATE_FINAL: &str =
1817
pub fn create_pb(
1918
mp: &MultiProgress,
2019
total_tests: u64,
21-
short_name: &str,
20+
short_name_padded: &str,
2221
all_bars: &mut Vec<ProgressBar>,
2322
) -> ProgressBar {
2423
let pb = mp.add(ProgressBar::new(total_tests));
25-
let short_name_padded = format!("{short_name:16}");
26-
let pb_style = ProgressStyle::with_template(&PB_TEMPLATE.replace("NAME", &short_name_padded))
24+
let pb_style = ProgressStyle::with_template(&PB_TEMPLATE.replace("NAME", short_name_padded))
2725
.unwrap()
2826
.progress_chars("##-");
2927

@@ -34,8 +32,7 @@ pub fn create_pb(
3432
}
3533

3634
/// Removes the status bar and replace it with a message.
37-
pub fn finalize_pb(pb: &ProgressBar, short_name: &str, c: &Completed) {
38-
let short_name_padded = format!("{short_name:16}");
35+
pub fn finalize_pb(pb: &ProgressBar, short_name_padded: &str, c: &Completed) {
3936
let f = c.failures;
4037

4138
// Use a tuple so we can use colors
@@ -64,13 +61,8 @@ pub fn finalize_pb(pb: &ProgressBar, short_name: &str, c: &Completed) {
6461
}
6562

6663
/// Print final messages after all tests are complete.
67-
pub fn finish(
68-
tests: &[TestInfo],
69-
total_elapsed: Duration,
70-
cfg: &Config,
71-
out: &mut Tee<'_>,
72-
) -> ExitCode {
73-
out.write_sout("\n\nResults:");
64+
pub fn finish(tests: &[TestInfo], total_elapsed: Duration, cfg: &Config) -> ExitCode {
65+
println!("\n\nResults:");
7466

7567
let mut failed_generators = 0;
7668
let mut stopped_generators = 0;
@@ -88,35 +80,34 @@ pub fn finish(
8880
"SUCCESS"
8981
};
9082

91-
out.write_sout(format!(
83+
println!(
9284
" {stat} for generator '{name}'. {passed}/{executed} passed in {elapsed:?}",
9385
name = t.name,
9486
passed = executed - failures,
95-
));
87+
);
9688

9789
if let Some(warning) = warning {
98-
out.write_sout(format!(" warning: {warning}"));
90+
println!(" warning: {warning}");
9991
}
10092

10193
match result {
10294
Ok(FinishedAll) => (),
10395
Err(EarlyExit::Timeout) => {
104-
out.write_sout(format!(" exited early; exceded {:?} timeout", cfg.timeout))
96+
println!(" exited early; exceded {:?} timeout", cfg.timeout)
97+
}
98+
Err(EarlyExit::MaxFailures) => {
99+
println!(" exited early; exceeded {:?} max failures", cfg.max_failures)
105100
}
106-
Err(EarlyExit::MaxFailures) => out.write_sout(format!(
107-
" exited early; exceeded {:?} max failures",
108-
cfg.max_failures
109-
)),
110101
}
111102
}
112103

113-
out.write_sout(format!(
104+
println!(
114105
"{passed}/{} tests succeeded in {total_elapsed:?} ({passed} passed, {} failed, {} stopped)",
115106
tests.len(),
116107
failed_generators,
117108
stopped_generators,
118109
passed = tests.len() - failed_generators - stopped_generators,
119-
));
110+
);
120111

121112
if failed_generators > 0 || stopped_generators > 0 {
122113
ExitCode::FAILURE
@@ -139,34 +130,3 @@ pub fn set_panic_hook(drop_bars: Vec<ProgressBar>) {
139130
hook(info);
140131
}));
141132
}
142-
143-
/// Open a file with a reasonable name that we can dump data to.
144-
pub fn create_log_file() -> (fs::File, String) {
145-
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
146-
let name = format!("parse-float-{now}.txt");
147-
(fs::OpenOptions::new().write(true).create_new(true).open(&name).unwrap(), name)
148-
}
149-
150-
/// Tee output to the file and either stdout or a progress bar.
151-
pub struct Tee<'a> {
152-
pub f: &'a fs::File,
153-
}
154-
155-
impl<'a> Tee<'a> {
156-
/// Write to both the file and above the multiprogress bar. Includes newline.
157-
pub fn write_mp(&mut self, mb: &MultiProgress, s: impl Into<String>) {
158-
let mut s = s.into();
159-
s.push('\n');
160-
self.f.write_all(s.as_bytes()).unwrap();
161-
s.pop();
162-
mb.println(s).unwrap();
163-
}
164-
165-
/// Write to both the file and stdout. Includes newline.
166-
pub fn write_sout(&mut self, s: impl Into<String>) {
167-
let mut s = s.into();
168-
s.push('\n');
169-
self.f.write_all(s.as_bytes()).unwrap();
170-
io::stdout().write_all(s.as_bytes()).unwrap();
171-
}
172-
}

0 commit comments

Comments
 (0)