Skip to content

Commit

Permalink
Make ::std tests optional
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Jun 25, 2023
1 parent bc41549 commit 21239b1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ jobs:
- run: cargo test --workspace --exclude no-std-examples --all-targets
- run: cargo test --workspace --exclude no-std-examples --doc
- run: cargo run --bin rune -- check --recursive --experimental scripts
- run: cargo run --bin rune -- test --recursive --experimental scripts
- run: cargo run --bin rune -- test --recursive --experimental scripts --opt include-std
20 changes: 20 additions & 0 deletions crates/rune/src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub(super) struct Flags {
/// Display one character per test instead of one line
#[arg(long, short = 'q')]
quiet: bool,
/// Also run tests for `::std`.
#[arg(long, long = "opt")]
options: Vec<String>,
/// Break on the first test failed.
#[arg(long)]
fail_fast: bool,
Expand Down Expand Up @@ -77,6 +80,19 @@ where

let mut build_error = false;

let mut include_std = false;

for opt in &flags.options {
match opt.as_str() {
"include-std" => {
include_std = true;
}
other => {
bail!("Unsupported option: {other}")
}
}
}

for e in entries {
let name = naming.name(&e);
let item = ItemBuf::with_crate(&name);
Expand Down Expand Up @@ -128,6 +144,10 @@ where
crate::doc::build("root", &mut artifacts, &context, &doc_visitors)?;

for test in artifacts.tests() {
if test.item.as_crate() == Some("std") && !include_std {
continue;
}

let mut sources = Sources::new();

let source = Source::new(test.item.to_string(), &test.content);
Expand Down
51 changes: 38 additions & 13 deletions crates/rune/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,6 @@ pub(crate) use rune_macros::__internal_impl_any;
/// }
/// }
///
/// /// Construct a new string wrapper.
/// #[rune::function(path = Self::new2)]
/// fn new2(string: &str) -> Self {
/// Self {
/// inner: string.into()
/// }
/// }
///
/// /// Uppercase the string inside of the string wrapper.
/// ///
/// /// # Examples
Expand All @@ -363,17 +355,50 @@ pub(crate) use rune_macros::__internal_impl_any;
/// /// assert_eq!(string.to_uppercase(), "HELLO");
/// /// ```
/// #[rune::function]
/// fn to_uppercase(&self) -> std::string::String {
/// self.inner.to_uppercase()
/// fn to_uppercase(&self) -> String {
/// String {
/// inner: self.inner.to_uppercase()
/// }
/// }
/// }
///
/// /// Construct a new empty string.
/// ///
/// /// # Examples
/// ///
/// /// ```rune
/// /// let string = String::empty();
/// /// assert_eq!(string, "hello");
/// /// ```
/// #[rune::function(path = String::empty)]
/// fn empty() -> String {
/// String {
/// inner: std::string::String::new()
/// }
/// }
///
/// /// Lowercase the string inside of the string wrapper.
/// ///
/// /// # Examples
/// ///
/// /// ```rune
/// /// let string = String::new("Hello");
/// /// assert_eq!(string.to_lowercase(), "hello");
/// /// ```
/// #[rune::function(instance)]
/// fn to_lowercase(this: &String) -> String {
/// String {
/// inner: this.inner.to_lowercase()
/// }
/// }
///
/// fn module() -> Result<Module, ContextError> {
/// let mut m = Module::new();
/// m.ty::<String>()?;
/// m.function_meta(String::new)?;
/// m.function_meta(String::new2)?;
/// m.function_meta(empty)?;
/// m.function_meta(String::to_uppercase)?;
/// m.function_meta(to_lowercase)?;
/// Ok(m)
/// }
/// ```
Expand All @@ -387,8 +412,8 @@ pub use rune_macros::function;
#[doc(hidden)]
pub use rune_macros::macro_;

/// Macro used to annotate native functions which can be loaded as attribute macros in
/// rune.
/// Macro used to annotate native functions which can be loaded as attribute
/// macros in rune.
///
/// See [`Module::macro_meta`].
#[doc(hidden)]
Expand Down

0 comments on commit 21239b1

Please sign in to comment.