diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7d9e93ba..42082c8f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -59,7 +59,7 @@ jobs: - name: Run unit tests run: cargo test --verbose - name: Test no-rustc mode - run: cargo check --no-default-features + run: cargo test --no-default-features build-std: strategy: diff --git a/Cargo.toml b/Cargo.toml index 4b817b82..90ce361d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ features = ["capture-spantrace"] [[test]] name = "integration" harness = false +required-features = ["rustc"] [[test]] name = "build_std" diff --git a/examples/rustc_basic.rs b/examples/rustc_basic.rs index c7c4c37f..7806d79c 100644 --- a/examples/rustc_basic.rs +++ b/examples/rustc_basic.rs @@ -1,6 +1,9 @@ +#[cfg(feature = "rustc")] use std::sync::atomic::Ordering; +#[cfg(feature = "rustc")] use ui_test::{run_tests, Config}; +#[cfg(feature = "rustc")] fn main() -> ui_test::color_eyre::Result<()> { let config = Config::rustc("examples_tests/rustc_basic"); let abort_check = config.abort_check.clone(); @@ -11,3 +14,8 @@ fn main() -> ui_test::color_eyre::Result<()> { // `.stderr` files. run_tests(config) } + +#[cfg(not(feature = "rustc"))] +fn main() -> ui_test::color_eyre::Result<()> { + Ok(()) +} diff --git a/src/config.rs b/src/config.rs index 681cb17c..4b498b3c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,4 @@ use regex::bytes::Regex; -#[cfg(feature = "rustc")] use spanned::Spanned; #[cfg(feature = "rustc")] @@ -70,6 +69,36 @@ pub struct Config { } impl Config { + /// Create a blank configuration that doesn't do anything interesting + pub fn dummy() -> Self { + let mut comment_defaults = Comments::default(); + comment_defaults.base().require_annotations = Spanned::dummy(true).into(); + Self { + host: Default::default(), + target: Default::default(), + root_dir: Default::default(), + program: CommandBuilder::cmd(""), + output_conflict_handling: OutputConflictHandling::Error, + bless_command: Default::default(), + out_dir: Default::default(), + skip_files: Default::default(), + filter_files: Default::default(), + threads: Default::default(), + list: Default::default(), + run_only_ignored: Default::default(), + filter_exact: Default::default(), + comment_defaults, + comment_start: "//", + custom_comments: Default::default(), + diagnostic_extractor: |_, _| Diagnostics { + rendered: Default::default(), + messages: Default::default(), + messages_from_unknown_file_or_line: Default::default(), + }, + abort_check: Default::default(), + } + } + /// Create a configuration for testing the output of running /// `rustc` on the test files. #[cfg(feature = "rustc")] diff --git a/src/lib.rs b/src/lib.rs index d125a3a7..39e94ce4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ use status_emitter::RevisionStyle; use status_emitter::{StatusEmitter, TestStatus}; use std::collections::VecDeque; use std::path::Path; +#[cfg(feature = "rustc")] use std::process::Command; use std::sync::atomic::Ordering; use std::sync::Arc; diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 8ebe55ff..0687cfa9 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -43,7 +43,7 @@ fn main() { bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap(); println!("parsed comments: {:#?}", comments); @@ -79,7 +79,7 @@ fn main() { bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap(); println!("parsed comments: {:#?}", comments); @@ -109,7 +109,7 @@ fn main() { bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap_err(); println!("parsed comments: {:#?}", errors); @@ -137,7 +137,7 @@ use std::mem; bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap(); println!("parsed comments: {:#?}", comments); @@ -163,7 +163,7 @@ use std::mem; bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap(); println!("parsed comments: {:#?}", comments); @@ -189,7 +189,7 @@ use std::mem; bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap_err(); println!("parsed comments: {:#?}", errors); @@ -223,7 +223,7 @@ use std::mem; bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap_err(); println!("parsed comments: {:#?}", errors); @@ -247,7 +247,7 @@ fn parse_x86_64() { bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap(); println!("parsed comments: {:#?}", comments); @@ -271,7 +271,7 @@ fn parse_two_only_filters() { bytes: 0..s.len(), }, ), - &Config::rustc(""), + &Config::dummy(), ) .unwrap(); println!("parsed comments: {:#?}", comments); diff --git a/src/tests.rs b/src/tests.rs index dcdafcf9..be2d78c6 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -11,7 +11,7 @@ fn config() -> Config { Config { root_dir: PathBuf::from("$RUSTROOT"), program: CommandBuilder::cmd("cake"), - ..Config::rustc(PathBuf::new()) + ..Config::dummy() } }