Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support no_std integration tests #1213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ default = ["std", "perf", "unicode", "regex-syntax/default"]

# ECOSYSTEM FEATURES

# The 'std' feature permits the regex crate to use the standard library. This
# is intended to support future use cases where the regex crate may be able
# to compile without std, and instead just rely on 'core' and 'alloc' (for
# example). Currently, this isn't supported, and removing the 'std' feature
# will prevent regex from compiling.
# The 'std' feature permits the regex crate to use the standard library.
std = [
"aho-corasick?/std",
"memchr?/std",
Expand Down
8 changes: 2 additions & 6 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ cd "$(dirname "$0")"
echo "===== DEFAULT FEATURES ====="
cargo test

# no-std mode is annoyingly difficult to test. Currently, the integration tests
# don't run. So for now, we just test that library tests run. (There aren't
# many because `regex` is just a wrapper crate.)
cargo test --no-default-features --lib

echo "===== DOC TESTS ====="
cargo test --doc

features=(
""
"std"
"std unicode"
"std unicode-perl"
Expand All @@ -36,7 +32,7 @@ features=(
)
for f in "${features[@]}"; do
echo "===== FEATURE: $f ====="
cargo test --test integration --no-default-features --features "$f"
cargo test --test integration --no-default-features --features="$f"
done

# And test the probably-forever-nightly-only 'pattern' feature...
Expand Down
12 changes: 12 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const BLACKLIST: &[&str] = &[
// Nothing to blacklist yet!
];

#[cfg(not(feature = "std"))]
pub(crate) fn nostd_compat<T: core::fmt::Debug>(
re: Result<T, regex::Error>,
) -> T {
assert!(
re.is_ok(),
"regex compilation failed: {}",
re.as_ref().unwrap_err(),
);
re.unwrap()
}

fn suite() -> anyhow::Result<regex_test::RegexTests> {
let _ = env_logger::try_init();

Expand Down
8 changes: 7 additions & 1 deletion tests/suite_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(feature = "std"))]
use crate::nostd_compat;
use {
anyhow::Result,
regex::bytes::{Regex, RegexBuilder},
Expand Down Expand Up @@ -90,7 +92,11 @@ fn compiler(
.case_insensitive(test.case_insensitive())
.unicode(test.unicode())
.line_terminator(test.line_terminator())
.build()?;
.build();
#[cfg(not(feature = "std"))]
let re = nostd_compat(re);
#[cfg(feature = "std")]
let re = re?; // Propagate any errors.
Ok(CompiledRegex::compiled(move |test| run_test(&re, test)))
}

Expand Down
8 changes: 7 additions & 1 deletion tests/suite_bytes_set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(feature = "std"))]
use crate::nostd_compat;
use {
anyhow::Result,
regex::bytes::{RegexSet, RegexSetBuilder},
Expand Down Expand Up @@ -66,6 +68,10 @@ fn compiler(
.case_insensitive(test.case_insensitive())
.unicode(test.unicode())
.line_terminator(test.line_terminator())
.build()?;
.build();
#[cfg(not(feature = "std"))]
let re = nostd_compat(re);
#[cfg(feature = "std")]
let re = re?; // Propagate any errors.
Ok(CompiledRegex::compiled(move |test| run_test(&re, test)))
}
8 changes: 7 additions & 1 deletion tests/suite_string.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(feature = "std"))]
use crate::nostd_compat;
use {
anyhow::Result,
regex::{Regex, RegexBuilder},
Expand Down Expand Up @@ -98,7 +100,11 @@ fn compiler(
.case_insensitive(test.case_insensitive())
.unicode(test.unicode())
.line_terminator(test.line_terminator())
.build()?;
.build();
#[cfg(not(feature = "std"))]
let re = nostd_compat(re);
#[cfg(feature = "std")]
let re = re?; // Propagate any errors.
Ok(CompiledRegex::compiled(move |test| run_test(&re, test)))
}

Expand Down
8 changes: 7 additions & 1 deletion tests/suite_string_set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(feature = "std"))]
use crate::nostd_compat;
use {
anyhow::Result,
regex::{RegexSet, RegexSetBuilder},
Expand Down Expand Up @@ -74,6 +76,10 @@ fn compiler(
.case_insensitive(test.case_insensitive())
.unicode(test.unicode())
.line_terminator(test.line_terminator())
.build()?;
.build();
#[cfg(not(feature = "std"))]
let re = nostd_compat(re);
#[cfg(feature = "std")]
let re = re?; // Propagate any errors.
Ok(CompiledRegex::compiled(move |test| run_test(&re, test)))
}