Skip to content

Commit e437fc2

Browse files
authored
Cleanup unused revision functionality from compiletest (rust-lang#2109)
1 parent ab91945 commit e437fc2

File tree

4 files changed

+57
-111
lines changed

4 files changed

+57
-111
lines changed

tools/compiletest/src/common.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::fmt;
99
use std::path::{Path, PathBuf};
1010
use std::str::FromStr;
1111

12-
use crate::util::PathBufExt;
1312
use std::time::Duration;
1413
use test::ColorConfig;
1514

@@ -153,22 +152,21 @@ pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
153152
config.build_base.join(relative_dir)
154153
}
155154

156-
/// Generates a unique name for the test, such as `testname.revision`.
157-
pub fn output_testname_unique(testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
158-
PathBuf::from(&testpaths.file.file_stem().unwrap()).with_extra_extension(revision.unwrap_or(""))
155+
/// Generates a unique name for the test.
156+
pub fn output_testname_unique(testpaths: &TestPaths) -> PathBuf {
157+
PathBuf::from(&testpaths.file.file_stem().unwrap())
159158
}
160159

161160
/// Absolute path to the directory where all output for the given
162-
/// test/revision should reside. Example:
163-
/// /path/to/build/host-triple/test/ui/relative/testname.revision/
164-
pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
165-
output_relative_path(config, &testpaths.relative_dir)
166-
.join(output_testname_unique(testpaths, revision))
161+
/// test should reside. Example:
162+
/// /path/to/build/host-triple/test/ui/relative/testname/
163+
pub fn output_base_dir(config: &Config, testpaths: &TestPaths) -> PathBuf {
164+
output_relative_path(config, &testpaths.relative_dir).join(output_testname_unique(testpaths))
167165
}
168166

169167
/// Absolute path to the base filename used as output for the given
170-
/// test/revision. Example:
171-
/// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
172-
pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
173-
output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
168+
/// test. Example:
169+
/// /path/to/build/host-triple/test/ui/relative/testname.mode/testname
170+
pub fn output_base_name(config: &Config, testpaths: &TestPaths) -> PathBuf {
171+
output_base_dir(config, testpaths).join(testpaths.file.file_stem().unwrap())
174172
}

tools/compiletest/src/header.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,20 @@ impl TestProps {
3434
}
3535
}
3636

37-
pub fn from_file(testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
37+
pub fn from_file(testfile: &Path, config: &Config) -> Self {
3838
let mut props = TestProps::new();
39-
props.load_from(testfile, cfg, config);
39+
props.load_from(testfile, config);
4040

4141
props
4242
}
4343

44-
/// Loads properties from `testfile` into `props`. If a property is
45-
/// tied to a particular revision `foo` (indicated by writing
46-
/// `//[foo]`), then the property is ignored unless `cfg` is
47-
/// `Some("foo")`.
48-
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
44+
/// Loads properties from `testfile` into `props`.
45+
fn load_from(&mut self, testfile: &Path, config: &Config) {
4946
let mut has_edition = false;
5047
if !testfile.is_dir() {
5148
let file = File::open(testfile).unwrap();
5249

53-
iter_header(testfile, file, &mut |revision, ln| {
54-
if revision.is_some() && revision != cfg {
55-
return;
56-
}
57-
50+
iter_header(testfile, file, &mut |ln| {
5851
if let Some(flags) = config.parse_compile_flags(ln) {
5952
self.compile_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
6053
}
@@ -93,7 +86,7 @@ impl TestProps {
9386
}
9487
}
9588

96-
fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str)) {
89+
fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(&str)) {
9790
if testfile.is_dir() {
9891
return;
9992
}
@@ -116,7 +109,7 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
116109
if ln.starts_with("fn") || ln.starts_with("mod") {
117110
return;
118111
} else if let Some(rest) = ln.strip_prefix(comment) {
119-
it(None, rest.trim_start());
112+
it(rest.trim_start());
120113
}
121114
}
122115
}
@@ -186,7 +179,6 @@ pub fn make_test_description<R: Read>(
186179
name: test::TestName,
187180
path: &Path,
188181
src: R,
189-
cfg: Option<&str>,
190182
) -> test::TestDesc {
191183
let mut ignore = false;
192184
let mut should_fail = false;
@@ -223,10 +215,7 @@ pub fn make_test_description<R: Read>(
223215
should_fail = true;
224216
}
225217

226-
iter_header(path, src, &mut |revision, ln| {
227-
if revision.is_some() && revision != cfg {
228-
return;
229-
}
218+
iter_header(path, src, &mut |ln| {
230219
should_fail |= config.parse_name_directive(ln, "should-fail");
231220
});
232221

tools/compiletest/src/main.rs

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn collect_expected_tests_from_dir(
369369
fs::create_dir_all(&build_dir.join(file_path.file_stem().unwrap())).unwrap();
370370
let paths =
371371
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
372-
tests.extend(make_test(config, &paths, inputs));
372+
tests.push(make_test(config, &paths, inputs));
373373
} else if file_path.is_dir() {
374374
// recurse on subdirectory
375375
let relative_file_path = relative_dir_path.join(file.file_name());
@@ -426,7 +426,7 @@ fn collect_exec_tests_from_dir(
426426
// Create directory for test and add it to the tests to be run
427427
fs::create_dir_all(&build_dir.join(file_path.file_stem().unwrap())).unwrap();
428428
let paths = TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
429-
tests.extend(make_test(config, &paths, inputs));
429+
tests.push(make_test(config, &paths, inputs));
430430
}
431431
Ok(())
432432
}
@@ -457,7 +457,7 @@ fn collect_rs_tests_from_dir(
457457
debug!("found test file: {:?}", file_path.display());
458458
let paths =
459459
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
460-
tests.extend(make_test(config, &paths, inputs))
460+
tests.push(make_test(config, &paths, inputs))
461461
} else if file_path.is_dir() {
462462
let relative_file_path = relative_dir_path.join(file.file_name());
463463
if &file_name != "auxiliary" {
@@ -484,39 +484,25 @@ pub fn is_test(file_name: &OsString) -> bool {
484484
!invalid_prefixes.iter().any(|p| file_name.starts_with(p))
485485
}
486486

487-
fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec<test::TestDescAndFn> {
487+
fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> test::TestDescAndFn {
488488
let test_path = PathBuf::from(&testpaths.file);
489-
let revisions = vec![None];
490-
491-
revisions
492-
.into_iter()
493-
.map(|revision: Option<&String>| {
494-
let src_file =
495-
std::fs::File::open(&test_path).expect("open test file to parse ignores");
496-
let cfg = revision.map(|v| &**v);
497-
let test_name = crate::make_test_name(config, testpaths, revision);
498-
let mut desc = make_test_description(config, test_name, &test_path, src_file, cfg);
499-
// Ignore tests that already run and are up to date with respect to inputs.
500-
if !config.force_rerun {
501-
desc.ignore |=
502-
is_up_to_date(config, testpaths, revision.map(|s| s.as_str()), inputs);
503-
}
504-
test::TestDescAndFn { desc, testfn: make_test_closure(config, testpaths, revision) }
505-
})
506-
.collect()
489+
490+
let src_file = std::fs::File::open(&test_path).expect("open test file to parse ignores");
491+
let test_name = crate::make_test_name(config, testpaths);
492+
let mut desc = make_test_description(config, test_name, &test_path, src_file);
493+
// Ignore tests that already run and are up to date with respect to inputs.
494+
if !config.force_rerun {
495+
desc.ignore |= is_up_to_date(config, testpaths, inputs);
496+
}
497+
test::TestDescAndFn { desc, testfn: make_test_closure(config, testpaths) }
507498
}
508499

509-
fn stamp(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
510-
output_base_dir(config, testpaths, revision).join("stamp")
500+
fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf {
501+
output_base_dir(config, testpaths).join("stamp")
511502
}
512503

513-
fn is_up_to_date(
514-
config: &Config,
515-
testpaths: &TestPaths,
516-
revision: Option<&str>,
517-
inputs: &Stamp,
518-
) -> bool {
519-
let stamp_name = stamp(config, testpaths, revision);
504+
fn is_up_to_date(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> bool {
505+
let stamp_name = stamp(config, testpaths);
520506
// Check timestamps.
521507
let inputs = inputs.clone();
522508

@@ -557,36 +543,22 @@ impl Stamp {
557543
}
558544
}
559545

560-
fn make_test_name(
561-
config: &Config,
562-
testpaths: &TestPaths,
563-
revision: Option<&String>,
564-
) -> test::TestName {
546+
fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
565547
// Convert a complete path to something like
566548
//
567549
// ui/foo/bar/baz.rs
568550
let path = PathBuf::from(config.src_base.file_name().unwrap())
569551
.join(&testpaths.relative_dir)
570552
.join(&testpaths.file.file_name().unwrap());
571553

572-
test::DynTestName(format!(
573-
"[{}] {}{}",
574-
config.mode,
575-
path.display(),
576-
revision.map_or("".to_string(), |rev| format!("#{rev}"))
577-
))
554+
test::DynTestName(format!("[{}] {}", config.mode, path.display()))
578555
}
579556

580-
fn make_test_closure(
581-
config: &Config,
582-
testpaths: &TestPaths,
583-
revision: Option<&String>,
584-
) -> test::TestFn {
557+
fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
585558
let config = config.clone();
586559
let testpaths = testpaths.clone();
587-
let revision = revision.cloned();
588560
test::DynTestFn(Box::new(move || {
589-
runtest::run(config, &testpaths, revision.as_deref());
561+
runtest::run(config, &testpaths);
590562
Ok(())
591563
}))
592564
}

tools/compiletest/src/runtest.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ pub fn dylib_env_var() -> &'static str {
4646
if cfg!(target_os = "macos") { "DYLD_LIBRARY_PATH" } else { "LD_LIBRARY_PATH" }
4747
}
4848

49-
pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) {
49+
pub fn run(config: Config, testpaths: &TestPaths) {
5050
if config.verbose {
5151
// We're going to be dumping a lot of info. Start on a new line.
5252
print!("\n\n");
5353
}
5454
debug!("running {:?}", testpaths.file.display());
55-
let props = TestProps::from_file(&testpaths.file, revision, &config);
55+
let props = TestProps::from_file(&testpaths.file, &config);
5656

57-
let cx = TestCx { config: &config, props: &props, testpaths, revision };
57+
let cx = TestCx { config: &config, props: &props, testpaths };
5858
create_dir_all(&cx.output_base_dir()).unwrap();
59-
cx.run_revision();
59+
cx.run();
6060
cx.create_stamp();
6161
}
6262

@@ -65,13 +65,11 @@ struct TestCx<'test> {
6565
config: &'test Config,
6666
props: &'test TestProps,
6767
testpaths: &'test TestPaths,
68-
revision: Option<&'test str>,
6968
}
7069

7170
impl<'test> TestCx<'test> {
72-
/// Code executed for each revision in turn (or, if there are no
73-
/// revisions, exactly once, with revision == None).
74-
fn run_revision(&self) {
71+
/// Code executed
72+
fn run(&self) {
7573
match self.config.mode {
7674
Kani => self.run_kani_test(),
7775
KaniFixme => self.run_kani_test(),
@@ -128,10 +126,8 @@ impl<'test> TestCx<'test> {
128126
}
129127

130128
fn dump_output(&self, out: &str, err: &str) {
131-
let revision = if let Some(r) = self.revision { format!("{r}.") } else { String::new() };
132-
133-
self.dump_output_file(out, &format!("{revision}out"));
134-
self.dump_output_file(err, &format!("{revision}err"));
129+
self.dump_output_file(out, "out");
130+
self.dump_output_file(err, "err");
135131
self.maybe_dump_to_stdout(out, err);
136132
}
137133

@@ -141,29 +137,23 @@ impl<'test> TestCx<'test> {
141137
}
142138

143139
/// Creates a filename for output with the given extension.
144-
/// E.g., `/.../testname.revision.mode/testname.extension`.
140+
/// E.g., `/.../testname.mode/testname.extension`.
145141
fn make_out_name(&self, extension: &str) -> PathBuf {
146142
self.output_base_name().with_extension(extension)
147143
}
148144

149-
/// The revision, ignored for incremental compilation since it wants all revisions in
150-
/// the same directory.
151-
fn safe_revision(&self) -> Option<&str> {
152-
self.revision
153-
}
154-
155145
/// Gets the absolute path to the directory where all output for the given
156-
/// test/revision should reside.
157-
/// E.g., `/path/to/build/host-triple/test/ui/relative/testname.revision.mode/`.
146+
/// test should reside.
147+
/// E.g., `/path/to/build/host-triple/test/ui/relative/testname.mode/`.
158148
fn output_base_dir(&self) -> PathBuf {
159-
output_base_dir(self.config, self.testpaths, self.safe_revision())
149+
output_base_dir(self.config, self.testpaths)
160150
}
161151

162152
/// Gets the absolute path to the base filename used as output for the given
163-
/// test/revision.
164-
/// E.g., `/.../relative/testname.revision.mode/testname`.
153+
/// test.
154+
/// E.g., `/.../relative/testname.mode/testname`.
165155
fn output_base_name(&self) -> PathBuf {
166-
output_base_name(self.config, self.testpaths, self.safe_revision())
156+
output_base_name(self.config, self.testpaths)
167157
}
168158

169159
fn maybe_dump_to_stdout(&self, out: &str, err: &str) {
@@ -177,10 +167,7 @@ impl<'test> TestCx<'test> {
177167
}
178168

179169
fn error(&self, err: &str) {
180-
match self.revision {
181-
Some(rev) => println!("\nerror in revision `{rev}`: {err}"),
182-
None => println!("\nerror: {err}"),
183-
}
170+
println!("\nerror: {err}");
184171
}
185172

186173
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
@@ -480,7 +467,7 @@ impl<'test> TestCx<'test> {
480467
}
481468

482469
fn create_stamp(&self) {
483-
let stamp = crate::stamp(self.config, self.testpaths, self.revision);
470+
let stamp = crate::stamp(self.config, self.testpaths);
484471
fs::write(&stamp, "we only support one configuration").unwrap();
485472
}
486473
}

0 commit comments

Comments
 (0)