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

Implement --skip flag in test runner #3803

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Added support for running tests in shared and service workers with ``wasm_bindgen_test_configure!` `run_in_shared_worker` and `run_in_service_worker`.
[#3804](https://github.com/rustwasm/wasm-bindgen/pull/3804)

* Accept the `--skip` flag with `wasm-bindgen-test-runner`.
[#3803](https://github.com/rustwasm/wasm-bindgen/pull/3803)

### Changed

* Stabilize `ClipboardEvent`.
Expand Down
47 changes: 35 additions & 12 deletions crates/test/src/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ struct State {
/// Include ignored tests.
include_ignored: Cell<bool>,

/// Tests to skip.
skip: RefCell<Vec<String>>,

/// Counter of the number of tests that have succeeded.
succeeded: Cell<usize>,

/// Counter of the number of tests that have been filtered
filtered: Cell<usize>,

/// Counter of the number of tests that have been ignored
ignored: Cell<usize>,

Expand Down Expand Up @@ -277,7 +283,9 @@ impl Context {
state: Rc::new(State {
filter: Default::default(),
include_ignored: Default::default(),
skip: Default::default(),
failures: Default::default(),
filtered: Default::default(),
ignored: Default::default(),
remaining: Default::default(),
running: Default::default(),
Expand All @@ -289,20 +297,25 @@ impl Context {

/// Inform this context about runtime arguments passed to the test
/// harness.
///
/// Eventually this will be used to support flags, but for now it's just
/// used to support test filters.
pub fn args(&mut self, args: Vec<JsValue>) {
// Here we want to reject all flags like `--foo` or `-f` as we don't
// support anything, and also we only support at most one non-flag
// argument as a test filter.
//
// Everything else is rejected.
let mut filter = self.state.filter.borrow_mut();
for arg in args {
let mut skip = self.state.skip.borrow_mut();

let mut args = args.into_iter();

while let Some(arg) = args.next() {
let arg = arg.as_string().unwrap();
if arg == "--include-ignored" {
self.state.include_ignored.set(true);
} else if arg == "--skip" {
skip.push(
args.next()
.expect("Argument to option 'skip' missing")
.as_string()
.unwrap(),
);
daxpedda marked this conversation as resolved.
Show resolved Hide resolved
} else if let Some(arg) = arg.strip_prefix("--skip=") {
skip.push(arg.to_owned())
} else if arg.starts_with('-') {
panic!("flag {} not supported", arg);
} else if filter.is_some() {
Expand Down Expand Up @@ -482,8 +495,16 @@ impl Context {
let filter = self.state.filter.borrow();
if let Some(filter) = &*filter {
if !name.contains(filter) {
let ignored = self.state.ignored.get();
self.state.ignored.set(ignored + 1);
let filtered = self.state.filtered.get();
self.state.filtered.set(filtered + 1);
return;
}
}

for skip in &*self.state.skip.borrow() {
if name.contains(skip) {
let filtered = self.state.filtered.get();
self.state.filtered.set(filtered + 1);
return;
}
}
Expand Down Expand Up @@ -628,11 +649,13 @@ impl State {
"test result: {}. \
{} passed; \
{} failed; \
{} ignored\n",
{} ignored; \
{} filtered out\n",
if failures.len() == 0 { "ok" } else { "FAILED" },
self.succeeded.get(),
failures.len(),
self.ignored.get(),
self.filtered.get(),
));
}

Expand Down