Skip to content

Commit

Permalink
Make everything work without the rustc feature
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 7, 2024
1 parent 00762eb commit 51c1edc
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ features = ["capture-spantrace"]
[[test]]
name = "integration"
harness = false
required-features = ["rustc"]

[[test]]
name = "build_std"
Expand Down
8 changes: 8 additions & 0 deletions examples/rustc_basic.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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(())
}
31 changes: 30 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use regex::bytes::Regex;
#[cfg(feature = "rustc")]
use spanned::Spanned;

#[cfg(feature = "rustc")]
Expand Down Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
Expand Down Expand Up @@ -79,7 +79,7 @@ fn main() {
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
Expand Down Expand Up @@ -109,7 +109,7 @@ fn main() {
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap_err();
println!("parsed comments: {:#?}", errors);
Expand Down Expand Up @@ -137,7 +137,7 @@ use std::mem;
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
Expand All @@ -163,7 +163,7 @@ use std::mem;
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
Expand All @@ -189,7 +189,7 @@ use std::mem;
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap_err();
println!("parsed comments: {:#?}", errors);
Expand Down Expand Up @@ -223,7 +223,7 @@ use std::mem;
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap_err();
println!("parsed comments: {:#?}", errors);
Expand All @@ -247,7 +247,7 @@ fn parse_x86_64() {
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
Expand All @@ -271,7 +271,7 @@ fn parse_two_only_filters() {
bytes: 0..s.len(),
},
),
&Config::rustc(""),
&Config::dummy(),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn config() -> Config {
Config {
root_dir: PathBuf::from("$RUSTROOT"),
program: CommandBuilder::cmd("cake"),
..Config::rustc(PathBuf::new())
..Config::dummy()
}
}

Expand Down

0 comments on commit 51c1edc

Please sign in to comment.