Skip to content

Commit 8e0d77d

Browse files
author
Ari Breitkreuz
committed
Address requested changes
1 parent eeb64bf commit 8e0d77d

File tree

7 files changed

+39
-48
lines changed

7 files changed

+39
-48
lines changed

crates/cli/src/bin/wasm-bindgen-test-runner/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,10 @@ fn coverage_args(tmpdir: &Path) -> Option<PathBuf> {
256256
}
257257

258258
// Profraw path is ignored if coverage isn't enabled
259-
env::var_os("WASM_BINDGEN_TEST_COVERAGE")?;
260-
log::warn!("Coverage support is still considered highly experimental!");
259+
env::var_os("WASM_BINDGEN_UNSTABLE_TEST_COVERAGE")?;
261260
// TODO coverage link to wasm-bindgen book documenting correct usage
262261

263-
match env::var_os("WASM_BINDGEN_TEST_PROFRAW_OUT") {
262+
match env::var_os("WASM_BINDGEN_TEST_UNSTABLE_PROFRAW_OUT") {
264263
Some(s) => {
265264
let mut buf = PathBuf::from(s);
266265
if buf.is_dir() {

crates/cli/src/bin/wasm-bindgen-test-runner/server.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,24 +245,21 @@ pub fn spawn(
245245
};
246246
return set_isolate_origin_headers(Response::from_data("text/html", s));
247247
} else if request.url() == "/__coverage/dump" {
248-
let profraw_path = coverage.as_ref().expect(
249-
"Received coverage dump request but server wasn't set up to accept coverage",
250-
);
251-
// This is run after all tests are done and dumps the data received in the request
252-
// into a single profraw file
253-
let mut profraw =
254-
std::fs::File::create(profraw_path).expect("Couldn't create .profraw for coverage");
255-
let mut data = Vec::new();
256-
request
257-
.data()
258-
.expect("Expected coverage data in body")
259-
.read_to_end(&mut data)
260-
.expect("Failed to read message body");
261-
262-
profraw
263-
.write_all(&data)
264-
.expect("Couldn't dump coverage data to profraw");
265-
return Response::text("Coverage dumped");
248+
fn internal_err(s: &str) -> Response {
249+
log::error!("{s}");
250+
let mut ret = Response::text(s);
251+
ret.status_code = 500;
252+
ret
253+
}
254+
let Some(profraw_path) = &coverage else {
255+
return internal_err(
256+
"Received coverage dump request but server wasn't set up to accept coverage",
257+
);
258+
};
259+
return match handle_coverage_dump(profraw_path, request) {
260+
Ok(()) => Response::empty_204(),
261+
Err(e) => internal_err(&format!("Failed to dump coverage: {e}")),
262+
};
266263
}
267264

268265
// Otherwise we need to find the asset here. It may either be in our
@@ -311,6 +308,21 @@ pub fn spawn(
311308
}
312309
}
313310

311+
fn handle_coverage_dump(profraw_path: &Path, request: &Request) -> anyhow::Result<()> {
312+
// This is run after all tests are done and dumps the data received in the request
313+
// into a single profraw file
314+
let mut profraw = std::fs::File::create(profraw_path)?;
315+
let mut data = Vec::new();
316+
if let Some(mut r_data) = request.data() {
317+
r_data.read_to_end(&mut data)?;
318+
}
319+
// Warnings about empty data should have already been handled by
320+
// the client
321+
322+
profraw.write_all(&data)?;
323+
Ok(())
324+
}
325+
314326
/*
315327
* Set the Cross-Origin-Opener-Policy and Cross-Origin_Embedder-Policy headers
316328
* on the Server response to enable worker context sharing, as described in:

crates/test/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ rust-version = "1.57"
1010

1111
[features]
1212
default = []
13-
experimental = ["coverage"]
14-
15-
coverage = ["minicov"]
13+
unstable-coverage = ["minicov"]
1614

1715
[dependencies]
1816
console_error_panic_hook = '0.1'

crates/test/src/coverage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use wasm_bindgen::prelude::wasm_bindgen;
22

3-
#[cfg(feature = "coverage")]
3+
#[cfg(feature = "unstable-coverage")]
44
#[wasm_bindgen]
55
pub fn __wbgtest_cov_dump() -> Vec<u8> {
66
let mut coverage = Vec::new();
@@ -16,10 +16,10 @@ pub fn __wbgtest_cov_dump() -> Vec<u8> {
1616
coverage
1717
}
1818

19-
/// Called when setting WASM_BINDGEN_TEST_COVERAGE but coverage feature is disabled.
19+
/// Called when setting WASM_BINDGEN_UNSTABLE_TEST_COVERAGE but coverage feature is disabled.
2020
/// Currently not being used because of issues in the interpreter regarding profiling
2121
/// information which cause an error before we get here.
22-
#[cfg(not(feature = "coverage"))]
22+
#[cfg(not(feature = "unstable-coverage"))]
2323
#[wasm_bindgen]
2424
pub fn __wbgtest_cov_dump() -> Vec<u8> {
2525
console_error!(

crates/test/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ macro_rules! console_log {
2121
)
2222
}
2323

24-
/// Helper macro which acts like `println!` only routes to `console.warn`
25-
/// instead.
26-
#[macro_export]
27-
macro_rules! console_warn {
28-
($($arg:tt)*) => (
29-
$crate::__rt::log_warn(&format_args!($($arg)*))
30-
)
31-
}
32-
3324
/// Helper macro which acts like `println!` only routes to `console.error`
3425
/// instead.
3526
#[macro_export]

crates/test/src/rt/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,6 @@ extern "C" {
237237
#[doc(hidden)]
238238
pub fn js_console_error(s: &str);
239239

240-
#[wasm_bindgen(js_namespace = console, js_name = warn)]
241-
#[doc(hidden)]
242-
pub fn js_console_warn(s: &str);
243-
244240
// General-purpose conversion into a `String`.
245241
#[wasm_bindgen(js_name = String)]
246242
fn stringify(val: &JsValue) -> String;
@@ -251,11 +247,6 @@ pub fn log(args: &fmt::Arguments) {
251247
js_console_log(&args.to_string());
252248
}
253249

254-
/// Internal implementation detail of the `console_warn!` macro.
255-
pub fn log_warn(args: &fmt::Arguments) {
256-
js_console_warn(&args.to_string());
257-
}
258-
259250
/// Internal implementation detail of the `console_error!` macro.
260251
pub fn log_error(args: &fmt::Arguments) {
261252
js_console_error(&args.to_string());

crates/wasm-interpreter/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Interpreter {
7474
/// the `module` passed to `interpret` below.
7575
pub fn new(module: &Module) -> Result<Interpreter, anyhow::Error> {
7676
let mut ret = Interpreter::default();
77-
ret.coverage = std::env::var_os("WASM_BINDGEN_TEST_COVERAGE").is_some();
77+
ret.coverage = std::env::var_os("WASM_BINDGEN_UNSTABLE_TEST_COVERAGE").is_some();
7878

7979
// The descriptor functions shouldn't really use all that much memory
8080
// (the LLVM call stack, now the wasm stack). To handle that let's give
@@ -227,7 +227,7 @@ impl Interpreter {
227227
log::debug!("arguments {:?}", args);
228228
let local = match &func.kind {
229229
walrus::FunctionKind::Local(l) => l,
230-
_ => panic!("can only call locally defined functions. If you're compiling with profiling information you might want to set WASM_BINDGEN_TEST_COVERAGE (--coverage flag in wasm-pack)"),
230+
_ => panic!("can only call locally defined functions. If you're compiling with profiling information you might want to set WASM_BINDGEN_UNSTABLE_TEST_COVERAGE (--coverage flag in wasm-pack)"),
231231
};
232232

233233
let entry = local.entry_block();
@@ -273,7 +273,7 @@ impl Frame<'_> {
273273
Instr::Const(c) => match c.value {
274274
Value::I32(n) => stack.push(n),
275275
Value::I64(_) if coverage => stack.push(0),
276-
_ => panic!("non-i32 constant. If you're compiling with profiling information you might want to set WASM_BINDGEN_TEST_COVERAGE (--coverage flag in wasm-pack)"),
276+
_ => panic!("non-i32 constant. If you're compiling with profiling information you might want to set WASM_BINDGEN_UNSTABLE_TEST_COVERAGE (--coverage flag in wasm-pack)"),
277277
},
278278
Instr::LocalGet(e) => stack.push(self.locals.get(&e.local).cloned().unwrap_or(0)),
279279
Instr::LocalSet(e) => {

0 commit comments

Comments
 (0)