Skip to content

Commit 8cdd467

Browse files
Add conditional turning off of cov info
1 parent 9ed899e commit 8cdd467

File tree

13 files changed

+61
-2
lines changed

13 files changed

+61
-2
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ xxx_debug_only_print_generated_code = [
4141
"wasm-bindgen-macro/xxx_debug_only_print_generated_code",
4242
]
4343

44+
## Turns off coverage generation for describe blocks
45+
unstable-coverage = ["wasm-bindgen-macro/unstable-coverage"]
46+
4447
[dependencies]
4548
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.90" }
4649
serde = { version = "1.0", optional = true }

crates/backend/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rust-version = "1.57"
1515
[features]
1616
spans = []
1717
extra-traits = ["syn/extra-traits"]
18+
unstable-coverage = []
1819

1920
[dependencies]
2021
bumpalo = "3.0.0"

crates/backend/src/codegen.rs

+18
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ impl TryToTokens for ast::LinkToModule {
160160
}
161161
}
162162

163+
#[cfg(feature = "unstable-coverage")]
164+
fn coverage() -> TokenStream {
165+
quote!(#[coverage(off)])
166+
}
167+
168+
#[cfg(not(feature = "unstable-coverage"))]
169+
fn coverage() -> TokenStream {
170+
quote!()
171+
}
172+
163173
impl ToTokens for ast::Struct {
164174
fn to_tokens(&self, tokens: &mut TokenStream) {
165175
let name = &self.rust_name;
@@ -169,10 +179,12 @@ impl ToTokens for ast::Struct {
169179
let new_fn = Ident::new(&shared::new_function(&name_str), Span::call_site());
170180
let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site());
171181
let unwrap_fn = Ident::new(&shared::unwrap_function(&name_str), Span::call_site());
182+
let coverage = coverage();
172183
let wasm_bindgen = &self.wasm_bindgen;
173184
(quote! {
174185
#[automatically_derived]
175186
impl #wasm_bindgen::describe::WasmDescribe for #name {
187+
#coverage
176188
fn describe() {
177189
use #wasm_bindgen::__wbindgen_if_not_std;
178190
__wbindgen_if_not_std! {
@@ -814,6 +826,7 @@ impl ToTokens for ast::ImportType {
814826
});
815827

816828
let no_deref = self.no_deref;
829+
let coverage = coverage();
817830

818831
(quote! {
819832
#[automatically_derived]
@@ -835,6 +848,7 @@ impl ToTokens for ast::ImportType {
835848
use #wasm_bindgen::__rt::core;
836849

837850
impl WasmDescribe for #rust_name {
851+
#coverage
838852
fn describe() {
839853
#description
840854
}
@@ -1048,6 +1062,7 @@ impl ToTokens for ast::ImportEnum {
10481062
let variant_paths_ref = &variant_paths;
10491063

10501064
let wasm_bindgen = &self.wasm_bindgen;
1065+
let coverage = coverage();
10511066

10521067
(quote! {
10531068
#(#attrs)*
@@ -1082,6 +1097,7 @@ impl ToTokens for ast::ImportEnum {
10821097
// It should really be using &str for all of these, but that requires some major changes to cli-support
10831098
#[automatically_derived]
10841099
impl #wasm_bindgen::describe::WasmDescribe for #name {
1100+
#coverage
10851101
fn describe() {
10861102
<#wasm_bindgen::JsValue as #wasm_bindgen::describe::WasmDescribe>::describe()
10871103
}
@@ -1404,6 +1420,7 @@ impl ToTokens for ast::Enum {
14041420
});
14051421
let try_from_cast_clauses = cast_clauses.clone();
14061422
let wasm_bindgen = &self.wasm_bindgen;
1423+
let coverage = coverage();
14071424
(quote! {
14081425
#[automatically_derived]
14091426
impl #wasm_bindgen::convert::IntoWasmAbi for #enum_name {
@@ -1441,6 +1458,7 @@ impl ToTokens for ast::Enum {
14411458

14421459
#[automatically_derived]
14431460
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
1461+
#coverage
14441462
fn describe() {
14451463
use #wasm_bindgen::describe::*;
14461464
inform(ENUM);

crates/backend/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))]
2828
#![deny(missing_docs)]
2929
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-backend/0.2")]
30+
#![cfg_attr(
31+
feature = "unstable-coverage",
32+
feature(allow_internal_unstable),
33+
allow(internal_features)
34+
)]
3035

3136
pub use crate::codegen::TryToTokens;
3237
pub use crate::error::Diagnostic;

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

-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ fn coverage_args(tmpdir: &Path) -> Option<PathBuf> {
264264
.map(|s| s.to_str().unwrap().to_string())
265265
.unwrap_or_default();
266266

267-
268267
match env::var_os("WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT") {
269268
Some(s) => {
270269
let mut buf = PathBuf::from(s);

crates/macro-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rust-version = "1.57"
1616
spans = ["wasm-bindgen-backend/spans"]
1717
extra-traits = ["syn/extra-traits"]
1818
strict-macro = []
19+
unstable-coverage = ["wasm-bindgen-backend/unstable-coverage"]
1920

2021
[dependencies]
2122
syn = { version = '2.0', features = ['visit', 'full'] }

crates/macro/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ proc-macro = true
1919
spans = ["wasm-bindgen-macro-support/spans"]
2020
xxx_debug_only_print_generated_code = []
2121
strict-macro = ["wasm-bindgen-macro-support/strict-macro"]
22+
unstable-coverage = ["wasm-bindgen-macro-support/unstable-coverage"]
2223

2324
[dependencies]
2425
wasm-bindgen-macro-support = { path = "../macro-support", version = "=0.2.90" }

crates/macro/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-macro/0.2")]
2+
#![cfg_attr(
3+
feature = "unstable-coverage",
4+
feature(allow_internal_unstable),
5+
allow(internal_features)
6+
)]
27

38
extern crate proc_macro;
49

510
use proc_macro::TokenStream;
611
use quote::quote;
712

813
#[proc_macro_attribute]
14+
#[cfg_attr(
15+
feature = "unstable-coverage",
16+
allow_internal_unstable(coverage_attribute)
17+
)]
918
pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
1019
match wasm_bindgen_macro_support::expand(attr.into(), input.into()) {
1120
Ok(tokens) => {

crates/test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rust-version = "1.57"
1010

1111
[features]
1212
default = []
13-
unstable-coverage = ["minicov"]
13+
unstable-coverage = ["minicov", "wasm-bindgen/unstable-coverage"]
1414

1515
[dependencies]
1616
console_error_panic_hook = '0.1'

src/closure.rs

+5
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ impl<T> WasmDescribe for Closure<T>
465465
where
466466
T: WasmClosure + ?Sized,
467467
{
468+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
468469
fn describe() {
469470
inform(EXTERNREF);
470471
}
@@ -565,6 +566,7 @@ macro_rules! doit {
565566
where $($var: FromWasmAbi + 'static,)*
566567
R: ReturnWasmAbi + 'static,
567568
{
569+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
568570
fn describe() {
569571
#[allow(non_snake_case)]
570572
unsafe extern "C" fn invoke<$($var: FromWasmAbi,)* R: ReturnWasmAbi>(
@@ -622,6 +624,7 @@ macro_rules! doit {
622624
where $($var: FromWasmAbi + 'static,)*
623625
R: ReturnWasmAbi + 'static,
624626
{
627+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
625628
fn describe() {
626629
#[allow(non_snake_case)]
627630
unsafe extern "C" fn invoke<$($var: FromWasmAbi,)* R: ReturnWasmAbi>(
@@ -763,6 +766,7 @@ where
763766
A: RefFromWasmAbi,
764767
R: ReturnWasmAbi + 'static,
765768
{
769+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
766770
fn describe() {
767771
#[allow(non_snake_case)]
768772
unsafe extern "C" fn invoke<A: RefFromWasmAbi, R: ReturnWasmAbi>(
@@ -809,6 +813,7 @@ where
809813
A: RefFromWasmAbi,
810814
R: ReturnWasmAbi + 'static,
811815
{
816+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
812817
fn describe() {
813818
#[allow(non_snake_case)]
814819
unsafe extern "C" fn invoke<A: RefFromWasmAbi, R: ReturnWasmAbi>(

src/convert/closures.rs

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ macro_rules! stack_closures {
5454
where $($var: FromWasmAbi,)*
5555
R: ReturnWasmAbi
5656
{
57+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
5758
fn describe() {
5859
inform(FUNCTION);
5960
inform($invoke::<$($var,)* R> as u32);
@@ -108,6 +109,7 @@ macro_rules! stack_closures {
108109
where $($var: FromWasmAbi,)*
109110
R: ReturnWasmAbi
110111
{
112+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
111113
fn describe() {
112114
inform(FUNCTION);
113115
inform($invoke_mut::<$($var,)* R> as u32);
@@ -177,6 +179,7 @@ where
177179
A: RefFromWasmAbi,
178180
R: ReturnWasmAbi,
179181
{
182+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
180183
fn describe() {
181184
inform(FUNCTION);
182185
inform(invoke1_ref::<A, R> as u32);
@@ -232,6 +235,7 @@ where
232235
A: RefFromWasmAbi,
233236
R: ReturnWasmAbi,
234237
{
238+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
235239
fn describe() {
236240
inform(FUNCTION);
237241
inform(invoke1_mut_ref::<A, R> as u32);

src/describe.rs

+12
Original file line numberDiff line numberDiff line change
@@ -103,32 +103,37 @@ cfg_if! {
103103
}
104104

105105
impl<T> WasmDescribe for *const T {
106+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
106107
fn describe() {
107108
inform(U32)
108109
}
109110
}
110111

111112
impl<T> WasmDescribe for *mut T {
113+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
112114
fn describe() {
113115
inform(U32)
114116
}
115117
}
116118

117119
impl<T: WasmDescribe> WasmDescribe for [T] {
120+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
118121
fn describe() {
119122
inform(SLICE);
120123
T::describe();
121124
}
122125
}
123126

124127
impl<'a, T: WasmDescribe + ?Sized> WasmDescribe for &'a T {
128+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
125129
fn describe() {
126130
inform(REF);
127131
T::describe();
128132
}
129133
}
130134

131135
impl<'a, T: WasmDescribe + ?Sized> WasmDescribe for &'a mut T {
136+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
132137
fn describe() {
133138
inform(REFMUT);
134139
T::describe();
@@ -166,46 +171,53 @@ if_std! {
166171
}
167172

168173
impl<T: WasmDescribeVector> WasmDescribe for Box<[T]> {
174+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
169175
fn describe() {
170176
T::describe_vector();
171177
}
172178
}
173179

174180
impl<T> WasmDescribe for Vec<T> where Box<[T]>: WasmDescribe {
181+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
175182
fn describe() {
176183
<Box<[T]>>::describe();
177184
}
178185
}
179186
}
180187

181188
impl<T: WasmDescribe> WasmDescribe for Option<T> {
189+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
182190
fn describe() {
183191
inform(OPTIONAL);
184192
T::describe();
185193
}
186194
}
187195

188196
impl WasmDescribe for () {
197+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
189198
fn describe() {
190199
inform(UNIT)
191200
}
192201
}
193202

194203
impl<T: WasmDescribe, E: Into<JsValue>> WasmDescribe for Result<T, E> {
204+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
195205
fn describe() {
196206
inform(RESULT);
197207
T::describe();
198208
}
199209
}
200210

201211
impl<T: WasmDescribe> WasmDescribe for Clamped<T> {
212+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
202213
fn describe() {
203214
inform(CLAMPED);
204215
T::describe();
205216
}
206217
}
207218

208219
impl WasmDescribe for JsError {
220+
#[cfg_attr(feature = "unstable-coverage", coverage(off))]
209221
fn describe() {
210222
JsValue::describe();
211223
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![no_std]
99
#![allow(coherence_leak_check)]
1010
#![doc(html_root_url = "https://docs.rs/wasm-bindgen/0.2")]
11+
#![cfg_attr(feature = "unstable-coverage", feature(coverage_attribute))]
1112

1213
use core::convert::TryFrom;
1314
use core::fmt;

0 commit comments

Comments
 (0)