chore(neon): Run all of the doc tests and run tests in debug mode
This commit is contained in:
parent
1e9bedb2d7
commit
d7ac291d97
@ -3,3 +3,4 @@
|
||||
# The following aliases simplify linting the entire workspace
|
||||
clippy-legacy = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,try-catch-api,legacy-runtime -- -A clippy::missing_safety_doc"
|
||||
clippy-napi = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features proc-macros,try-catch-api,napi-experimental -- -A clippy::missing_safety_doc"
|
||||
neon-test = "test --no-default-features --features napi-experimental"
|
||||
|
||||
2
.github/workflows/linux.yml
vendored
2
.github/workflows/linux.yml
vendored
@ -32,7 +32,7 @@ jobs:
|
||||
- name: install build-essential
|
||||
run: sudo apt-get install -y build-essential
|
||||
- name: run cargo test
|
||||
run: xvfb-run --auto-servernum cargo test --release -- --nocapture
|
||||
run: xvfb-run --auto-servernum cargo neon-test -- --nocapture
|
||||
- name: run CLI test
|
||||
working-directory: ./create-neon
|
||||
run: npm test
|
||||
|
||||
2
.github/workflows/macos.yml
vendored
2
.github/workflows/macos.yml
vendored
@ -34,7 +34,7 @@ jobs:
|
||||
# # https://github.com/nodejs/node-gyp/issues/1933#issuecomment-586915535
|
||||
# run: npm install -g node-gyp@latest
|
||||
- name: run cargo test
|
||||
run: cargo test --release
|
||||
run: cargo neon-test
|
||||
- name: run CLI test
|
||||
working-directory: ./create-neon
|
||||
run: npm test
|
||||
|
||||
2
.github/workflows/windows.yml
vendored
2
.github/workflows/windows.yml
vendored
@ -43,7 +43,7 @@ jobs:
|
||||
# run: npm install -g node-gyp@latest
|
||||
- run: npm config set msvs_version 2019
|
||||
- name: run cargo test
|
||||
run: cargo test --release
|
||||
run: cargo neon-test
|
||||
env:
|
||||
LIBCLANG_PATH: ${{ runner.temp }}/llvm/bin
|
||||
- name: run CLI test
|
||||
|
||||
@ -21,9 +21,8 @@ use legacy as macros;
|
||||
/// be called each time the module is initialized in a context.
|
||||
///
|
||||
/// ```ignore
|
||||
/// # use neon::prelude::*;
|
||||
/// #[neon::main]
|
||||
/// fn my_module(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
/// fn init(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
/// let version = cx.string("1.0.0");
|
||||
///
|
||||
/// cx.export_value("version", version)?;
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
//! a convenient shorthand for `CallContext<JsObject>`):
|
||||
//!
|
||||
//! ```
|
||||
//! # use neon::prelude::*;
|
||||
//! fn hello(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
//! Ok(cx.string("hello Neon"))
|
||||
//! }
|
||||
@ -25,11 +26,15 @@
|
||||
//! with JavaScript:
|
||||
//!
|
||||
//! ```
|
||||
//! # #[cfg(feature = "neon-macros")] {
|
||||
//! # use neon::prelude::*;
|
||||
//! # fn hello(_: FunctionContext) -> JsResult<JsValue> { todo!() }
|
||||
//! #[neon::main]
|
||||
//! fn main(cx: ModuleContext) -> NeonResult<()> {
|
||||
//! fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
//! cx.export_function("hello", hello)?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! ## Memory Management
|
||||
@ -43,16 +48,19 @@
|
||||
//! write a simple string scanner that counts whitespace in a JavaScript string and
|
||||
//! returns a [`JsNumber`](crate::types::JsNumber):
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```
|
||||
//! # #[cfg(feature = "napi-1")] {
|
||||
//! # use neon::prelude::*;
|
||||
//! fn count_whitespace(mut cx: FunctionContext) -> JsResult<JsNumber> {
|
||||
//! let s: Handle<JsString> = cx.argument(0)?;
|
||||
//! let contents = s.value();
|
||||
//! let contents = s.value(&mut cx);
|
||||
//! let count = contents
|
||||
//! .chars() // iterate over the characters
|
||||
//! .filter(|c| c.is_whitespace()) // select the whitespace chars
|
||||
//! .count(); // count the resulting chars
|
||||
//! Ok(cx.number(count))
|
||||
//! Ok(cx.number(count as f64))
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! In this example, `s` is assigned a handle to a string, which ensures that the string
|
||||
@ -74,10 +82,12 @@
|
||||
//! a Neon function has to work with several temporary handles on each pass through
|
||||
//! the loop:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```
|
||||
//! # #[cfg(feature = "napi-1")] {
|
||||
//! # use neon::prelude::*;
|
||||
//! # fn iterate(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
//! let iterator = /* ... */; // iterator object
|
||||
//! let next = iterator.get("next")? // iterator's `next` method
|
||||
//! let iterator = cx.argument::<JsObject>(0)?; // iterator object
|
||||
//! let next = iterator.get(&mut cx, "next")? // iterator's `next` method
|
||||
//! .downcast_or_throw::<JsFunction, _>(&mut cx)?;
|
||||
//! let mut numbers = vec![]; // results vector
|
||||
//! let mut done = false; // loop controller
|
||||
@ -85,16 +95,19 @@
|
||||
//! while !done {
|
||||
//! done = cx.execute_scoped(|mut cx| { // temporary scope
|
||||
//! let args: Vec<Handle<JsValue>> = vec![];
|
||||
//! let obj = next.call(&mut cx, iterator, args)?; // temporary object
|
||||
//! let obj = next.call(&mut cx, iterator, args)? // temporary object
|
||||
//! .downcast_or_throw::<JsObject, _>(&mut cx)?;
|
||||
//! let number = obj.get(&mut cx, "value")? // temporary number
|
||||
//! .downcast_or_throw::<JsNumber, _>(&mut cx)?
|
||||
//! .value(&mut cx);
|
||||
//! numbers.push(number);
|
||||
//! Ok(obj.get(&mut cx, "done")? // temporary boolean
|
||||
//! .downcast_or_throw::<JsBoolean, _>(&mut cx)?
|
||||
//! value(&mut cx));
|
||||
//! .value(&mut cx))
|
||||
//! })?;
|
||||
//! }
|
||||
//! # Ok(cx.undefined())
|
||||
//! # }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use types::Value;
|
||||
|
||||
pub trait SuperType<T: Value> {
|
||||
fn upcast_internal(T) -> Self;
|
||||
fn upcast_internal(v: T) -> Self;
|
||||
}
|
||||
|
||||
@ -16,9 +16,15 @@
|
||||
//! type `Handle<T>`. For example, we can call
|
||||
//! [`JsNumber::value()`](crate::types::JsNumber::value) on a `Handle<JsNumber>`:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! let n: Handle<JsNumber> = cx.argument(0)?;
|
||||
//! let v = n.value(&mut cx); // JsNumber::value()
|
||||
//! ```
|
||||
//! # #[cfg(feature = "napi-1")] {
|
||||
//! # use neon::prelude::*;
|
||||
//! # fn run(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
//! let n: Handle<JsNumber> = cx.argument(0)?;
|
||||
//! let v = n.value(&mut cx); // JsNumber::value()
|
||||
//! # Ok(cx.undefined())
|
||||
//! # }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! ## Example
|
||||
@ -27,22 +33,25 @@
|
||||
//! `width` and `height`, and multiplies them together as numbers. Each JavaScript
|
||||
//! value in the calculation is stored locally in a `Handle`.
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```
|
||||
//! # #[cfg(feature = "napi-1")] {
|
||||
//! # use neon::prelude::*;
|
||||
//! fn area(mut cx: FunctionContext) -> JsResult<JsNumber> {
|
||||
//! let rect: Handle<JsObject> = cx.argument(0)?;
|
||||
//!
|
||||
//! let width: Handle<JsNumber> = rect
|
||||
//! .get(&mut cx, "width")?
|
||||
//! .downcast(&mut cx)?;
|
||||
//! .downcast_or_throw(&mut cx)?;
|
||||
//! let w: f64 = width.value(&mut cx);
|
||||
//!
|
||||
//! let height: Handle<JsNumber> = rect
|
||||
//! .get(&mut cx, "height")?
|
||||
//! .downcast(&mut cx)?;
|
||||
//! .downcast_or_throw(&mut cx)?;
|
||||
//! let h: f64 = height.value(&mut cx);
|
||||
//!
|
||||
//! Ok(cx.number(w * h))
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
pub(crate) mod internal;
|
||||
|
||||
23
src/lib.rs
23
src/lib.rs
@ -43,7 +43,8 @@
|
||||
//! point to be executed when the module is loaded. This function can have
|
||||
//! any name but is conventionally called `main`:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```
|
||||
//! # #[cfg(feature = "neon-macros")] {
|
||||
//! # use neon::prelude::*;
|
||||
//! #
|
||||
//! # fn hello(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
@ -51,17 +52,18 @@
|
||||
//! # }
|
||||
//! #
|
||||
//! #[neon::main]
|
||||
//! fn main(cx: ModuleContext) -> NeonResult<()> {
|
||||
//! fn init(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
//! cx.export_function("hello", hello)?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! The example code generated by `neon init neon` exports a single
|
||||
//! function via [`ModuleContext::export_function`](context::ModuleContext::export_function).
|
||||
//! The `hello` function is defined just above `main` in `src/lib.rs`:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```
|
||||
//! # use neon::prelude::*;
|
||||
//! #
|
||||
//! fn hello(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
@ -161,13 +163,19 @@ macro_rules! register_module {
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// ```
|
||||
/// # #[cfg(feature = "n-api")] {
|
||||
/// # use neon::prelude::*;
|
||||
/// # fn foo(mut cx: FunctionContext) -> JsResult<JsUndefined> { Ok(cx.undefined()) }
|
||||
/// # fn bar(mut cx: FunctionContext) -> JsResult<JsUndefined> { Ok(cx.undefined()) }
|
||||
/// # fn baz(mut cx: FunctionContext) -> JsResult<JsUndefined> { Ok(cx.undefined()) }
|
||||
/// register_module!(mut cx, {
|
||||
/// cx.export_function("foo", foo)?;
|
||||
/// cx.export_function("bar", bar)?;
|
||||
/// cx.export_function("baz", baz)?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! register_module {
|
||||
@ -513,10 +521,7 @@ mod tests {
|
||||
|
||||
log("static_test");
|
||||
|
||||
run(
|
||||
"cargo test --release",
|
||||
&project_root().join("test").join("static"),
|
||||
);
|
||||
run("cargo test", &project_root().join("test").join("static"));
|
||||
}
|
||||
|
||||
// Only run the static tests in Beta. This will catch changes to error reporting
|
||||
@ -570,7 +575,7 @@ mod tests {
|
||||
log("dynamic_cargo_test");
|
||||
|
||||
let test_dynamic_cargo = project_root().join("test").join("dynamic").join("native");
|
||||
run("cargo test --release", &test_dynamic_cargo);
|
||||
run("cargo test", &test_dynamic_cargo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
//! throwing an exception if the argument is not of the right type or extracting the property
|
||||
//! fails:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```
|
||||
//! # use neon::prelude::*;
|
||||
//! fn get_message(mut cx: FunctionContext) -> JsResult<JsValue> {
|
||||
//! let obj: Handle<JsObject> = cx.argument(0)?;
|
||||
//! let prop: Handle<JsValue> = obj.get(&mut cx, "message")?;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
"author": "The Neon Community",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"install": "node ../../cli/bin/cli.js build --release",
|
||||
"install": "node ../../cli/bin/cli.js build",
|
||||
"test": "mocha --timeout 5000 --recursive lib"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user