webidl: Add logging and use env_logger in the tests

This commit is contained in:
Nick Fitzgerald 2018-06-01 15:24:48 -07:00
parent 346d2fda22
commit 8faebc56f2
5 changed files with 64 additions and 13 deletions

View File

@ -18,7 +18,7 @@ matrix:
- rust: nightly
before_install: rustup component add rustfmt-preview --toolchain nightly
script: (cd crates/webidl && cargo test)
env: RUST_BACKTRACE=1
env: RUST_BACKTRACE=1 RUST_LOG=wasm_bindgen_webidl
# Dist linux binary
- env: TARGET=x86_64-unknown-linux-musl DEPLOY=1

View File

@ -1,6 +1,6 @@
[package]
name = "wasm-bindgen-webidl"
version = "0.1.0"
version = "0.2.11"
authors = ["Nick Fitzgerald <fitzgen@gmail.com>"]
[[test]]
@ -12,12 +12,14 @@ name = "webidl-expected"
path = "tests/expected/lib.rs"
[dev-dependencies]
diff = "0.1.11"
env_logger = "0.5.10"
wasm-bindgen = { version = "=0.2.11", path = "../..", default-features = false }
wasm-bindgen-backend = { version = "=0.2.11", path = "../backend", features = ["extra-traits"] }
diff = "0.1.11"
[dependencies]
failure = "0.1"
log = "0.4.1"
proc-macro2 = "0.4"
quote = '0.6'
syn = { version = '0.14', features = ['full'] }

View File

@ -9,6 +9,8 @@ emitted for the types and methods described in the WebIDL.
#![deny(missing_debug_implementations)]
extern crate failure;
#[macro_use]
extern crate log;
extern crate proc_macro2;
extern crate quote;
extern crate syn;
@ -99,7 +101,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition {
| webidl::ast::Definition::Includes(..)
| webidl::ast::Definition::Mixin(..)
| webidl::ast::Definition::Namespace(..)
| webidl::ast::Definition::Typedef(..) => Ok(()),
| webidl::ast::Definition::Typedef(..) => {
warn!("Unsupported WebIDL definition: {:?}", self);
Ok(())
}
}
}
}
@ -113,7 +118,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Interface {
interface.webidl_parse(program, ())
}
// TODO
webidl::ast::Interface::Callback(..) | webidl::ast::Interface::Partial(..) => Ok(()),
webidl::ast::Interface::Callback(..) | webidl::ast::Interface::Partial(..) => {
warn!("Unsupported WebIDL interface: {:?}", self);
Ok(())
}
}
}
}
@ -153,7 +161,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::InterfaceMember {
| webidl::ast::InterfaceMember::Const(_)
| webidl::ast::InterfaceMember::Iterable(_)
| webidl::ast::InterfaceMember::Maplike(_)
| webidl::ast::InterfaceMember::Setlike(_) => Ok(()),
| webidl::ast::InterfaceMember::Setlike(_) => {
warn!("Unsupported WebIDL interface member: {:?}", self);
Ok(())
}
}
}
}
@ -167,7 +178,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Operation {
// TODO
webidl::ast::Operation::Special(_)
| webidl::ast::Operation::Static(_)
| webidl::ast::Operation::Stringifier(_) => Ok(()),
| webidl::ast::Operation::Stringifier(_) => {
warn!("Unsupported WebIDL operation: {:?}", self);
Ok(())
}
}
}
}
@ -276,14 +290,26 @@ impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation {
fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> {
let fn_name = match self.name {
None => return Ok(()),
None => {
warn!(
"Operations without a name are unsupported. Skipping {:?}",
self
);
return Ok(());
}
Some(ref name) => Ident::new(name, proc_macro2::Span::call_site()),
};
let (output, ret) = match self.return_type {
webidl::ast::ReturnType::Void => (syn::ReturnType::Default, None),
webidl::ast::ReturnType::NonVoid(ref ty) => match webidl_ty_to_syn_ty(ty) {
None => return Ok(()),
None => {
warn!(
"Operation's return type is not yet supported: {:?}. Skipping bindings for {:?}",
ty, self
);
return Ok(());
}
Some(ty) => (
syn::ReturnType::Type(Default::default(), Box::new(ty.clone())),
Some(ty),
@ -303,14 +329,30 @@ impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation {
arguments.push(self_ref_ty);
for arg in &self.arguments {
if arg.optional || arg.variadic {
// We don't support optional or variadic functions yet; skip
// bindings for this this whole function.
if arg.optional {
warn!(
"Optional arguments are not supported yet. Skipping bindings for {:?}",
self
);
return Ok(());
}
if arg.variadic {
warn!(
"Variadic arguments are not supported yet. Skipping bindings for {:?}",
self
);
return Ok(());
}
match webidl_ty_to_syn_ty(&arg.type_) {
None => return Ok(()),
None => {
warn!(
"Argument's type is not yet supported: {:?}. Skipping bindings for {:?}",
arg.type_, self
);
return Ok(());
}
Some(ty) => {
inputs.push(simple_fn_arg(
proc_macro2::Ident::new(&arg.name, proc_macro2::Span::call_site()),

View File

@ -1,4 +1,5 @@
extern crate diff;
extern crate env_logger;
extern crate proc_macro2;
extern crate syn;
extern crate wasm_bindgen_backend as backend;

View File

@ -1,4 +1,5 @@
use diff;
use env_logger;
use std::io::{self, Write};
use std::process;
use std::sync::{Once, ONCE_INIT};
@ -90,6 +91,11 @@ fn strip_wasm_bindgen_generated(source: String) -> String {
}
pub fn assert_compile(webidl: &str, expected: &str) {
static INIT_ENV_LOGGER: Once = ONCE_INIT;
INIT_ENV_LOGGER.call_once(|| {
env_logger::init();
});
let actual = wb_webidl::compile(webidl).expect("should compile the webidl source OK");
let (actual, actual_stderr) = rustfmt(actual);