Skip to content

Commit 590c610

Browse files
committed
compiletest: make some internals pub for use as a library
Make Config, TestPaths, CollectedTest, CollectedTestDesc, ShouldFail, FileDirectives, parse_config and collect_and_make_tests public so that external tools can depend on compiletest as a library and use its test collection infrastructure directly. r? jackh726
1 parent c771f6e commit 590c610

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

src/tools/compiletest/src/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl CodegenBackend {
235235
/// FIXME: audit these options to make sure we are not hashing less than necessary for build stamp
236236
/// (for changed test detection).
237237
#[derive(Debug, Clone)]
238-
pub(crate) struct Config {
238+
pub struct Config {
239239
/// Some [`TestMode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
240240
/// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
241241
///
@@ -1170,7 +1170,7 @@ pub(crate) fn query_rustc_output(
11701170

11711171
/// Path information for a single test file.
11721172
#[derive(Debug, Clone)]
1173-
pub(crate) struct TestPaths {
1173+
pub struct TestPaths {
11741174
/// Full path to the test file.
11751175
///
11761176
/// For example:
@@ -1183,7 +1183,7 @@ pub(crate) struct TestPaths {
11831183
///
11841184
/// For example:
11851185
/// - `/home/ferris/rust/tests/run-make/emit`
1186-
pub(crate) file: Utf8PathBuf,
1186+
pub file: Utf8PathBuf,
11871187

11881188
/// Subset of the full path that excludes the suite directory and the
11891189
/// test filename. For tests in the root of their test suite directory,
@@ -1192,7 +1192,7 @@ pub(crate) struct TestPaths {
11921192
/// For example:
11931193
/// - `file`: `/home/ferris/rust/tests/ui/warnings/hello-world.rs`
11941194
/// - `relative_dir`: `warnings`
1195-
pub(crate) relative_dir: Utf8PathBuf,
1195+
pub relative_dir: Utf8PathBuf,
11961196
}
11971197

11981198
/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.

src/tools/compiletest/src/executor.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,26 +325,26 @@ fn get_concurrency() -> usize {
325325
}
326326

327327
/// Information that was historically needed to create a libtest `TestDescAndFn`.
328-
pub(crate) struct CollectedTest {
329-
pub(crate) desc: CollectedTestDesc,
330-
pub(crate) config: Arc<Config>,
331-
pub(crate) testpaths: TestPaths,
332-
pub(crate) revision: Option<String>,
328+
pub struct CollectedTest {
329+
pub desc: CollectedTestDesc,
330+
pub config: Arc<Config>,
331+
pub testpaths: TestPaths,
332+
pub revision: Option<String>,
333333
}
334334

335335
/// Information that was historically needed to create a libtest `TestDesc`.
336-
pub(crate) struct CollectedTestDesc {
337-
pub(crate) name: String,
338-
pub(crate) filterable_path: Utf8PathBuf,
339-
pub(crate) ignore: bool,
340-
pub(crate) ignore_message: Option<Cow<'static, str>>,
341-
pub(crate) should_fail: ShouldFail,
336+
pub struct CollectedTestDesc {
337+
pub name: String,
338+
pub filterable_path: Utf8PathBuf,
339+
pub ignore: bool,
340+
pub ignore_message: Option<Cow<'static, str>>,
341+
pub should_fail: ShouldFail,
342342
}
343343

344344
/// Tests with `//@ should-fail` are tests of compiletest itself, and should
345345
/// be reported as successful if and only if they would have _failed_.
346346
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
347-
pub(crate) enum ShouldFail {
347+
pub enum ShouldFail {
348348
No,
349349
Yes,
350350
}

src/tools/compiletest/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ mod read2;
2323
mod runtest;
2424
mod util;
2525

26+
// Re-export types needed by external tools that use compiletest as a library.
27+
pub use common::{Config, TestPaths};
28+
pub use executor::{CollectedTest, CollectedTestDesc, ShouldFail};
29+
2630
use core::panic;
2731
use std::collections::HashSet;
2832
use std::fmt::Write;
@@ -40,19 +44,18 @@ use walkdir::WalkDir;
4044

4145
use self::directives::{EarlyProps, make_test_description};
4246
use crate::common::{
43-
CodegenBackend, CompareMode, Config, Debugger, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
47+
CodegenBackend, CompareMode, Debugger, PassMode, TestMode, UI_EXTENSIONS,
4448
expected_output_path, output_base_dir, output_relative_path,
4549
};
4650
use crate::directives::{AuxProps, DirectivesCache, FileDirectives};
4751
use crate::edition::parse_edition;
48-
use crate::executor::CollectedTest;
4952

5053
/// Creates the `Config` instance for this invocation of compiletest.
5154
///
5255
/// The config mostly reflects command-line arguments, but there might also be
5356
/// some code here that inspects environment variables or even runs executables
5457
/// (e.g. when discovering debugger versions).
55-
fn parse_config(args: Vec<String>) -> Config {
58+
pub fn parse_config(args: Vec<String>) -> Config {
5659
let mut opts = Options::new();
5760
opts.reqopt("", "compile-lib-path", "path to host shared libraries", "PATH")
5861
.reqopt("", "run-lib-path", "path to target shared libraries", "PATH")
@@ -653,7 +656,7 @@ impl TestCollector {
653656
/// FIXME(Zalathar): Now that we no longer rely on libtest, try to overhaul
654657
/// test discovery to take into account the filters/tests specified on the
655658
/// command-line, instead of having to enumerate everything.
656-
fn collect_and_make_tests(config: Arc<Config>) -> Vec<CollectedTest> {
659+
pub fn collect_and_make_tests(config: Arc<Config>) -> Vec<CollectedTest> {
657660
debug!("making tests from {}", config.src_test_suite_root);
658661
let common_inputs_stamp = common_inputs_stamp(&config);
659662
let modified_tests =

0 commit comments

Comments
 (0)