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

Improve CI testing #3333

Merged
merged 6 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
44 changes: 25 additions & 19 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,13 @@ jobs:
run: cargo test --no-run --profile ci
# this order is faster according to rust-analyzer
- name: Build
run: cargo build --all-targets --quiet --profile ci
run: cargo build --all-targets --quiet --profile ci --features annex-b,intl,experimental
- name: Install latest nextest
uses: taiki-e/install-action@nextest
- name: Test with nextest
run: cargo nextest run --profile ci --cargo-profile ci --features annex-b,intl,experimental
- name: Test docs
run: cargo test --doc --profile ci --features annex-b,intl,experimental
- name: Build boa_ast crate
run: cargo build -p boa_ast
- name: Build boa_cli crate
run: cargo build -p boa_cli
- name: Build boa_parser crate
run: cargo build -p boa_parser
- name: Build boa_runtime crate
run: cargo build -p boa_runtime

msrv:
name: Minimum supported Rust version
Expand Down Expand Up @@ -106,27 +98,41 @@ jobs:
override: true
profile: minimal
components: rustfmt, clippy
- uses: actions-rs/[email protected]
- name: Install cargo-workspaces
uses: actions-rs/[email protected]
with:
crate: cargo-workspaces
- name: Install cargo-fuzz
uses: actions-rs/[email protected]
with:
crate: cargo-fuzz
version: latest
- uses: Swatinem/rust-cache@v2
with:
key: misc

- name: Format (rustfmt)
run: cargo fmt --all --check

- name: Lint (All features)
run: cargo clippy --all-features --all-targets
run: cargo workspaces exec cargo clippy --all-features --all-targets -- -D warnings
- name: Lint (No features)
run: cargo clippy -p boa_engine --no-default-features --all-targets
run: cargo workspaces exec cargo clippy --no-default-features --all-targets -- -D warnings

- name: Generate documentation
run: cargo doc -v --document-private-items --all-features
- name: Build
run: cargo build --all-targets --quiet --profile ci

- name: Build (All features)
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved
run: cargo workspaces exec cargo build --all-features --all-targets --profile ci
- name: Build (No features)
run: cargo workspaces exec cargo build --no-default-features --all-targets --profile ci

- name: Build fuzzers
run: cargo fuzz build -s none
- run: cd boa_examples
- name: Build examples
run: cargo build --quiet --profile ci
- name: Run example classes
run: cargo run --bin classes --profile ci

- name: Run examples
run: |
cd boa_examples
cargo run -p boa_examples --bin 2>&1 \
| grep -E '^ ' \
| xargs -n1 sh -c 'cargo run -p boa_examples --profile ci --bin $0 || exit 255'
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boa_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository.workspace = true
rust-version.workspace = true

[features]
serde = ["dep:serde", "boa_interner/serde", "bitflags/serde"]
serde = ["dep:serde", "boa_interner/serde", "bitflags/serde", "num-bigint/serde"]
arbitrary = ["dep:arbitrary", "boa_interner/arbitrary", "num-bigint/arbitrary"]

[dependencies]
Expand Down
21 changes: 14 additions & 7 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
clippy::pedantic,
clippy::nursery,
)]
#![allow(clippy::option_if_let_else, clippy::redundant_pub_crate)]

use boa_ast as _;
#![allow(
unused_crate_dependencies,
clippy::option_if_let_else,
clippy::redundant_pub_crate
)]

mod debug;
mod helper;
Expand All @@ -88,16 +90,21 @@ use std::{
println,
};

#[cfg(all(
target_arch = "x86_64",
target_os = "linux",
target_env = "gnu",
feature = "dhat"
))]
use jemallocator as _;

#[cfg(all(
target_arch = "x86_64",
target_os = "linux",
target_env = "gnu",
not(feature = "dhat")
))]
#[cfg_attr(
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
global_allocator
)]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[cfg(feature = "dhat")]
Expand Down
2 changes: 2 additions & 0 deletions boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ mod runtime_limits;
#[cfg(feature = "flowgraph")]
pub mod flowgraph;

// TODO: see if this can be exposed on all features.
#[allow(unused_imports)]
pub(crate) use opcode::{Instruction, InstructionIterator, Opcode, VaryingOperandKind};
pub use runtime_limits::RuntimeLimits;
pub use {
Expand Down
8 changes: 8 additions & 0 deletions boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ macro_rules! generate_opcodes {
impl Opcode {
const MAX: usize = 2usize.pow(8) * 3;

// TODO: see if this can be exposed on all features.
#[allow(unused)]
const NAMES: [&'static str; Self::MAX] = [
$(<generate_opcodes!(name $Variant $(=> $mapping)?)>::NAME),*,
$(<generate_opcodes!(name $Variant $(=> $mapping)?)>::NAME),*,
Expand All @@ -406,6 +408,8 @@ macro_rules! generate_opcodes {

/// Name of this opcode.
#[must_use]
// TODO: see if this can be exposed on all features.
#[allow(unused)]
pub(crate) const fn as_str(self) -> &'static str {
Self::NAMES[self as usize]
}
Expand Down Expand Up @@ -505,6 +509,8 @@ macro_rules! generate_opcodes {
/// Get the [`Opcode`] of the [`Instruction`].
#[inline]
#[must_use]
// TODO: see if this can be exposed on all features.
#[allow(unused)]
pub(crate) const fn opcode(&self) -> Opcode {
match self {
$(
Expand Down Expand Up @@ -2193,6 +2199,8 @@ pub(crate) struct InstructionIterator<'bytecode> {
pc: usize,
}

// TODO: see if this can be exposed on all features.
#[allow(unused)]
impl<'bytecode> InstructionIterator<'bytecode> {
/// Create a new [`InstructionIterator`] from bytecode array.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions boa_examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ boa_interner.workspace = true
boa_gc.workspace = true
boa_parser.workspace = true
boa_runtime.workspace = true
chrono.workspace = true
smol = "1.3.0"
futures-util = "0.3.28"
3 changes: 1 addition & 2 deletions boa_examples/src/bin/commuter_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ impl<'ast> VisitorMut<'ast> for CommutorVisitor {
}

fn main() {
let mut parser =
Parser::new(Source::from_filepath(Path::new("boa_examples/scripts/calc.js")).unwrap());
let mut parser = Parser::new(Source::from_filepath(Path::new("./scripts/calc.js")).unwrap());
let mut ctx = Context::default();

let mut script = parser.parse_script(ctx.interner_mut()).unwrap();
Expand Down
59 changes: 37 additions & 22 deletions boa_examples/src/bin/jsdate.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
use boa_engine::{js_string, object::builtins::JsDate, Context, JsResult, JsValue};
use boa_engine::{
context::HostHooks, js_string, object::builtins::JsDate, Context, JsResult, JsValue,
};
use chrono::{DateTime, FixedOffset, LocalResult, NaiveDateTime, TimeZone};

struct CustomTimezone;

// This pins the local timezone to a system-agnostic value; in this case, UTC+3
impl HostHooks for CustomTimezone {
fn local_from_utc(&self, utc: NaiveDateTime) -> DateTime<FixedOffset> {
FixedOffset::east_opt(3 * 3600)
.unwrap()
.from_utc_datetime(&utc)
}

fn local_from_naive_local(&self, local: NaiveDateTime) -> LocalResult<DateTime<FixedOffset>> {
FixedOffset::east_opt(3 * 3600)
.unwrap()
.from_local_datetime(&local)
}
}

fn main() -> JsResult<()> {
let context = &mut Context::default();

let date = JsDate::new(context);
let hooks: &dyn HostHooks = &CustomTimezone;
let context = &mut Context::builder().host_hooks(hooks).build().unwrap();

// 823230245000.0
JsDate::utc(
let timestamp = JsDate::utc(
&[
JsValue::new(96),
JsValue::new(1),
Expand All @@ -16,42 +34,39 @@ fn main() -> JsResult<()> {
JsValue::new(5),
],
context,
)?;
// reference date: 2022-07-16T06:27:32.087241439
)?
.as_number()
.unwrap();

assert_eq!(timestamp, 823230245000.0);

// Gets the current time in UTC time.
let date = JsDate::new(context);

// sets day of the month to 24
date.set_date(24, context)?;
// 2022-07-24T06:27:11.567

// sets date to 1st of January 2000
date.set_full_year(&[2000.into(), 0.into(), 1.into()], context)?;
// 2000-01-01T06:26:53.984

// sets time to 10H:10M:10S:10mS
date.set_hours(&[23.into(), 23.into(), 23.into(), 23.into()], context)?;
// Is 2000-01-01T17:53:23.023
// Should be 2000-01-01T23:23:23.023

// sets milliseconds to 999
date.set_milliseconds(999, context)?;
// 2000-01-01T17:40:10.999

// sets time to 12M:12S:12ms
date.set_minutes(&[12.into(), 12.into(), 12.into()], context)?;
// Is 2000-01-01T17:42:12.012
// Should be 2000-01-01T17:12:12:012

// sets month to 9 and day to 9
// sets month to 9 (the 10th) and day to 9
date.set_month(&[9.into(), 9.into()], context)?;
// 2000-10-09T04:42:12.012

// set seconds to 59 and ms to 59
date.set_seconds(&[59.into(), 59.into()], context)?;
// 2000-10-09T04:42:59.059

assert_eq!(
date.to_json(context)?,
JsValue::from(js_string!("2000-10-09T17:42:59.059Z"))
JsValue::from(js_string!("2000-10-09T20:12:59.059Z"))
);

assert_eq!(
Expand All @@ -61,17 +76,17 @@ fn main() -> JsResult<()> {

assert_eq!(
date.to_iso_string(context)?,
JsValue::from(js_string!("2000-10-09T17:42:59.059Z"))
JsValue::from(js_string!("2000-10-09T20:12:59.059Z"))
);

assert_eq!(
date.to_time_string(context)?,
JsValue::from(js_string!("23:12:59 GMT+0530"))
JsValue::from(js_string!("23:12:59 GMT+0300"))
);

assert_eq!(
date.to_string(context)?,
JsValue::from(js_string!("Mon Oct 09 2000 23:12:59 GMT+0530"))
JsValue::from(js_string!("Mon Oct 09 2000 23:12:59 GMT+0300"))
);

Ok(())
Expand Down
46 changes: 23 additions & 23 deletions boa_examples/src/bin/loadfile.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// This example shows how to load, parse and execute JS code from a source file
// (./scripts/helloworld.js)

use std::path::Path;
use std::{error::Error, path::Path};

use boa_engine::{Context, Source};
use boa_engine::{js_string, property::Attribute, Context, Source};
use boa_runtime::Console;

fn main() {
/// Adds the custom runtime to the context.
fn add_runtime(context: &mut Context<'_>) {
// We first add the `console` object, to be able to call `console.log()`.
let console = Console::init(context);
context
.register_global_property(js_string!(Console::NAME), console, Attribute::all())
.expect("the console builtin shouldn't exist");
}

fn main() -> Result<(), Box<dyn Error>> {
let js_file_path = "./scripts/helloworld.js";

match Source::from_filepath(Path::new(js_file_path)) {
Ok(src) => {
// Instantiate the execution context
let mut context = Context::default();
// Parse the source code
match context.eval(src) {
Ok(res) => {
println!(
"{}",
res.to_string(&mut context).unwrap().to_std_string_escaped()
);
}
Err(e) => {
// Pretty print the error
eprintln!("Uncaught {e}");
}
};
}
Err(msg) => eprintln!("Error: {msg}"),
}
let source = Source::from_filepath(Path::new(js_file_path))?;

// Instantiate the execution context
let mut context = Context::default();
// Add the runtime intrisics
add_runtime(&mut context);
// Parse the source code and print the result
println!("{}", context.eval(source)?.display());

Ok(())
}
Loading
Loading