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

Use trybuild for testing expected proc macro errors #205

Merged
merged 2 commits into from
Jun 19, 2019
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ travis-ci = { repository = "TeXitoi/structopt" }
clap = { version = "2.33", default-features = false }
structopt-derive = { path = "structopt-derive", version = "0.3.0" }

[dev-dependencies]
trybuild = "1.0.5"

[workspace]
12 changes: 12 additions & 0 deletions tests/macro-errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed

#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}
23 changes: 23 additions & 0 deletions tests/ui/bool_default_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, default_value = true)]
b: bool,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/bool_default_value.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/bool_default_value.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: default_value is meaningless for bool
23 changes: 23 additions & 0 deletions tests/ui/bool_required.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, required = true)]
b: bool,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/bool_required.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/bool_required.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: required is meaningless for bool
32 changes: 32 additions & 0 deletions tests/ui/flatten_and_doc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt)]
struct DaemonOpts {
#[structopt(short)]
user: String,
#[structopt(short)]
group: String,
}

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
/// Opts.
#[structopt(flatten)]
opts: DaemonOpts,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/flatten_and_doc.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/flatten_and_doc.rs:21:10
|
21 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: methods and doc comments are not allowed for flattened entry
31 changes: 31 additions & 0 deletions tests/ui/flatten_and_methods.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt)]
struct DaemonOpts {
#[structopt(short)]
user: String,
#[structopt(short)]
group: String,
}

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, flatten)]
opts: DaemonOpts,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/flatten_and_methods.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/flatten_and_methods.rs:21:10
|
21 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: methods and doc comments are not allowed for flattened entry
31 changes: 31 additions & 0 deletions tests/ui/flatten_and_parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt)]
struct DaemonOpts {
#[structopt(short)]
user: String,
#[structopt(short)]
group: String,
}

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(flatten, parse(from_occurrences))]
opts: DaemonOpts,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/flatten_and_parse.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/flatten_and_parse.rs:21:10
|
21 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: parse attribute is not allowed for flattened entry
24 changes: 24 additions & 0 deletions tests/ui/literal_list_element.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(test(1, 2))]
debug: bool,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}

7 changes: 7 additions & 0 deletions tests/ui/literal_list_element.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/literal_list_element.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: unsupported option: test ( 1 , 2 )
23 changes: 23 additions & 0 deletions tests/ui/non_existent_attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, non_existing_attribute = 1)]
debug: bool,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/non_existent_attr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0599]: no method named `non_existing_attribute` found for type `structopt::clap::Arg<'_, '_>` in the current scope
--> $DIR/non_existent_attr.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^

For more information about this error, try `rustc --explain E0599`.
24 changes: 24 additions & 0 deletions tests/ui/non_literal_attr_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, aliases = &["debug", "dbg"])]
debug: bool,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}

7 changes: 7 additions & 0 deletions tests/ui/non_literal_attr_value.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/non_literal_attr_value.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: invalid structopt syntax: expected literal: # [ structopt ( short , aliases = & [ "debug" , "dbg" ] ) ]
22 changes: 22 additions & 0 deletions tests/ui/opt_opt_nonpositional.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
n: Option<Option<u32>>,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/opt_opt_nonpositional.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/opt_opt_nonpositional.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: Option<Option<T>> type is meaningless for positional argument
22 changes: 22 additions & 0 deletions tests/ui/opt_vec_nonpositional.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
n: Option<Vec<u32>>,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/opt_vec_nonpositional.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/opt_vec_nonpositional.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: Option<Vec<T>> type is meaningless for positional argument
23 changes: 23 additions & 0 deletions tests/ui/option_default_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate structopt;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, default_value = 1)]
n: Option<u32>,
}

fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 7 additions & 0 deletions tests/ui/option_default_value.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: proc-macro derive panicked
--> $DIR/option_default_value.rs:13:10
|
13 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
= help: message: default_value is meaningless for Option
Loading