Skip to content

Commit

Permalink
Add an option to print skipped items
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Feb 20, 2019
1 parent af6d9a3 commit 9b8a31e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ctest"
version = "0.2.9"
version = "0.2.10"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand Down
40 changes: 40 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct TestGenerator {
out_dir: Option<PathBuf>,
defines: Vec<(String, Option<String>)>,
cfg: Vec<(String, Option<String>)>,
verbose_skip: bool,
skip_fn: Box<Fn(&str) -> bool>,
skip_fn_ptrcheck: Box<Fn(&str) -> bool>,
skip_static: Box<Fn(&str) -> bool>,
Expand Down Expand Up @@ -127,6 +128,7 @@ impl TestGenerator {
out_dir: None,
defines: Vec::new(),
cfg: Vec::new(),
verbose_skip: false,
skip_fn: Box::new(|_| false),
skip_fn_ptrcheck: Box::new(|_| false),
skip_static: Box::new(|_| false),
Expand Down Expand Up @@ -339,6 +341,12 @@ impl TestGenerator {
self
}

/// Skipped item names are printed to `stderr` if `v` is `true`.
pub fn verbose_skip(&mut self, v: bool) -> &mut Self {
self.verbose_skip = v;
self
}

/// Configures how a Rust type name is translated to a C type name.
///
/// The closure is given a Rust type name as well as a boolean indicating
Expand Down Expand Up @@ -1080,6 +1088,9 @@ impl<'a> Generator<'a> {

fn test_type(&mut self, name: &str, ty: &ast::Ty) {
if (self.opts.skip_type)(name) {
if self.opts.verbose_skip {
eprintln!("skipping type \"{}\"", name);
}
return;
}
let c = self.rust_ty_to_c_ty(name);
Expand All @@ -1089,6 +1100,9 @@ impl<'a> Generator<'a> {

fn test_struct(&mut self, ty: &str, s: &ast::VariantData) {
if (self.opts.skip_struct)(ty) {
if self.opts.verbose_skip {
eprintln!("skipping struct \"{}\"", ty);
}
return;
}

Expand Down Expand Up @@ -1117,6 +1131,10 @@ impl<'a> Generator<'a> {
let name = name.to_string();

if (self.opts.skip_field)(ty, &name) {
if self.opts.verbose_skip {
eprintln!("skipping field \"{}\" of struct \"{}\"", name, ty);
}

continue;
}

Expand Down Expand Up @@ -1164,6 +1182,10 @@ impl<'a> Generator<'a> {
));

if (self.opts.skip_field_type)(ty, &name.to_string()) {
if self.opts.verbose_skip {
eprintln!("skipping field type \"{}\" of struct \"{}\"", name, ty);
}

continue;
}

Expand Down Expand Up @@ -1269,6 +1291,10 @@ impl<'a> Generator<'a> {

fn test_sign(&mut self, rust: &str, c: &str, ty: &ast::Ty) {
if (self.opts.skip_signededness)(rust) {
if self.opts.verbose_skip {
eprintln!("skipping sign \"{}\"", rust);
}

return;
}
if !self.has_sign(ty) {
Expand Down Expand Up @@ -1326,6 +1352,10 @@ impl<'a> Generator<'a> {
#[clippy::allow(clippy::similar_names)]
fn test_const(&mut self, name: &str, rust_ty: &str) {
if (self.opts.skip_const)(name) {
if self.opts.verbose_skip {
eprintln!("skipping const \"{}\"", name);
}

return;
}

Expand Down Expand Up @@ -1407,6 +1437,9 @@ impl<'a> Generator<'a> {
abi: Abi,
) {
if (self.opts.skip_fn)(name) {
if self.opts.verbose_skip {
eprintln!("skipping fn \"{}\"", name);
}
return;
}
let c_name = (self.opts.fn_cname)(name, c_name.as_ref().map(|s| &**s));
Expand Down Expand Up @@ -1456,6 +1489,10 @@ impl<'a> Generator<'a> {
name = name,
skip = (self.opts.skip_fn_ptrcheck)(name)
));
if self.opts.verbose_skip && (self.opts.skip_fn_ptrcheck)(name) {
eprintln!("skipping fn ptr check \"{}\"", name);
}

self.tests.push(format!("fn_{}", name));
}

Expand All @@ -1468,6 +1505,9 @@ impl<'a> Generator<'a> {
mutbl: bool,
) {
if (self.opts.skip_static)(name) {
if self.opts.verbose_skip {
eprintln!("skipping static \"{}\"", name);
}
return;
}

Expand Down

0 comments on commit 9b8a31e

Please sign in to comment.