From 60c25b45e7eef8f23f92988cc03fc5dd69c366e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Sat, 18 Feb 2023 08:30:04 +0000 Subject: [PATCH] Fix doc tests and add CI check (#2606) This Pull Request fixes #2605. It changes the following: - Adds a CI check to run `cargo test --doc` since `nextest` doesn't support doc tests at the moment. - Fixes the failing doc tests. --- .github/workflows/rust.yml | 2 ++ boa_engine/src/class.rs | 3 ++- boa_engine/src/context/hooks.rs | 2 +- boa_engine/src/context/mod.rs | 3 ++- boa_engine/src/lib.rs | 2 ++ boa_engine/src/object/mod.rs | 10 ++++++++-- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 475e6b5e77..1405c4b015 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -57,6 +57,8 @@ jobs: uses: taiki-e/install-action@nextest - name: Test with nextest run: cargo nextest run --profile ci --cargo-profile ci --features intl + - name: Test docs + run: cargo test --doc --profile ci --features intl misc: name: Misc diff --git a/boa_engine/src/class.rs b/boa_engine/src/class.rs index 18cd0d71b8..8654190958 100644 --- a/boa_engine/src/class.rs +++ b/boa_engine/src/class.rs @@ -3,10 +3,11 @@ //! Native classes are implemented through the [`Class`][class-trait] trait. //! ``` //! # use boa_engine::{ +//! # NativeFunction, //! # property::Attribute, //! # class::{Class, ClassBuilder}, //! # Context, JsResult, JsValue, -//! # builtins::JsArgs, +//! # JsArgs, //! # }; //! # use boa_gc::{Finalize, Trace}; //! # diff --git a/boa_engine/src/context/hooks.rs b/boa_engine/src/context/hooks.rs index f4b2802b89..46c887f11e 100644 --- a/boa_engine/src/context/hooks.rs +++ b/boa_engine/src/context/hooks.rs @@ -31,7 +31,7 @@ use super::intrinsics::Intrinsics; /// } /// } /// let hooks = Hooks; // Can have additional state. -/// let context = &mut ContextBuilder::new().host_hooks(&hooks).build(); +/// let context = &mut ContextBuilder::new().host_hooks(&hooks).build().unwrap(); /// let result = context.eval_script(Source::from_bytes(r#"eval("let a = 5")"#)); /// assert_eq!(result.unwrap_err().to_string(), "TypeError: eval calls not available"); /// ``` diff --git a/boa_engine/src/context/mod.rs b/boa_engine/src/context/mod.rs index e15ff9e27d..d1856ff63c 100644 --- a/boa_engine/src/context/mod.rs +++ b/boa_engine/src/context/mod.rs @@ -172,11 +172,12 @@ impl Context<'_> { result } + // TODO: remove `ignore` after we implement module execution /// Evaluates the given module `src` by compiling down to bytecode, then interpreting the /// bytecode into a value. /// /// # Examples - /// ``` + /// ```ignore /// # use boa_engine::{Context, Source}; /// let mut context = Context::default(); /// diff --git a/boa_engine/src/lib.rs b/boa_engine/src/lib.rs index 43281e9a5e..7ac37de191 100644 --- a/boa_engine/src/lib.rs +++ b/boa_engine/src/lib.rs @@ -135,6 +135,7 @@ mod tests; pub mod prelude { pub use crate::{ error::{JsError, JsNativeError, JsNativeErrorKind}, + native_function::NativeFunction, object::JsObject, Context, JsBigInt, JsResult, JsString, JsValue, }; @@ -149,6 +150,7 @@ pub use crate::{ bigint::JsBigInt, context::Context, error::{JsError, JsNativeError, JsNativeErrorKind}, + native_function::NativeFunction, string::JsString, symbol::JsSymbol, value::JsValue, diff --git a/boa_engine/src/object/mod.rs b/boa_engine/src/object/mod.rs index 3f58304537..fa6c780527 100644 --- a/boa_engine/src/object/mod.rs +++ b/boa_engine/src/object/mod.rs @@ -2040,12 +2040,18 @@ impl<'ctx, 'host> FunctionObjectBuilder<'ctx, 'host> { /// # Examples /// /// ``` -/// # use boa_engine::{Context, JsValue, object::ObjectInitializer, property::Attribute}; +/// # use boa_engine::{ +/// # Context, +/// # JsValue, +/// # NativeFunction, +/// # object::ObjectInitializer, +/// # property::Attribute +/// # }; /// let mut context = Context::default(); /// let object = ObjectInitializer::new(&mut context) /// .property("hello", "world", Attribute::all()) /// .property(1, 1, Attribute::all()) -/// .function(|_, _, _| Ok(JsValue::undefined()), "func", 0) +/// .function(NativeFunction::from_fn_ptr(|_, _, _| Ok(JsValue::undefined())), "func", 0) /// .build(); /// ``` ///