From 21239b15db215debdaa26130db3e88b103a0a2ff Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sun, 25 Jun 2023 07:35:52 +0200 Subject: [PATCH] Make ::std tests optional --- .github/workflows/ci.yml | 2 +- crates/rune/src/cli/tests.rs | 20 ++++++++++++++ crates/rune/src/lib.rs | 51 +++++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94dc9375b..a31bae319 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/crates/rune/src/cli/tests.rs b/crates/rune/src/cli/tests.rs index 82d834f71..7c2dc3427 100644 --- a/crates/rune/src/cli/tests.rs +++ b/crates/rune/src/cli/tests.rs @@ -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, /// Break on the first test failed. #[arg(long)] fail_fast: bool, @@ -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); @@ -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); diff --git a/crates/rune/src/lib.rs b/crates/rune/src/lib.rs index 74e318f52..5a93f38c9 100644 --- a/crates/rune/src/lib.rs +++ b/crates/rune/src/lib.rs @@ -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 @@ -363,8 +355,40 @@ 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() /// } /// } /// @@ -372,8 +396,9 @@ pub(crate) use rune_macros::__internal_impl_any; /// let mut m = Module::new(); /// m.ty::()?; /// 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) /// } /// ``` @@ -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)]