-
Notifications
You must be signed in to change notification settings - Fork 97
Fix some redaction bugs #112
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,7 @@ fn missing_option_value() { | |
| struct Cmd { | ||
| #[argh(option)] | ||
| /// fooey | ||
| msg: String, | ||
| _msg: String, | ||
| } | ||
|
|
||
| let e = Cmd::from_args(&["cmdname"], &["--msg"]) | ||
|
|
@@ -539,10 +539,10 @@ mod fuchsia_commandline_tools_rubric { | |
| struct TwoSwitches { | ||
| #[argh(switch, short = 'a')] | ||
| /// a | ||
| a: bool, | ||
| _a: bool, | ||
| #[argh(switch, short = 'b')] | ||
| /// b | ||
| b: bool, | ||
| _b: bool, | ||
| } | ||
|
|
||
| /// Running switches together is not allowed | ||
|
|
@@ -558,7 +558,7 @@ mod fuchsia_commandline_tools_rubric { | |
| struct OneOption { | ||
| #[argh(option)] | ||
| /// some description | ||
| foo: String, | ||
| _foo: String, | ||
| } | ||
|
|
||
| /// Do not use an equals punctuation or similar to separate the key and value. | ||
|
|
@@ -666,15 +666,15 @@ mod fuchsia_commandline_tools_rubric { | |
| /// A type for testing `--help`/`help` | ||
| struct HelpTopLevel { | ||
| #[argh(subcommand)] | ||
| sub: HelpFirstSub, | ||
| _sub: HelpFirstSub, | ||
| } | ||
|
|
||
| #[derive(FromArgs, Debug)] | ||
| #[argh(subcommand, name = "first")] | ||
| /// First subcommmand for testing `help`. | ||
| struct HelpFirstSub { | ||
| #[argh(subcommand)] | ||
| sub: HelpSecondSub, | ||
| _sub: HelpSecondSub, | ||
| } | ||
|
|
||
| #[derive(FromArgs, Debug)] | ||
|
|
@@ -912,7 +912,7 @@ fn redact_arg_values_no_args() { | |
| struct Cmd { | ||
| #[argh(option)] | ||
| /// a msg param | ||
| msg: Option<String>, | ||
| _msg: Option<String>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &[]).unwrap(); | ||
|
|
@@ -926,25 +926,53 @@ fn redact_arg_values_optional_arg() { | |
| struct Cmd { | ||
| #[argh(option)] | ||
| /// a msg param | ||
| msg: Option<String>, | ||
| _msg: Option<String>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["--msg", "hello"]).unwrap(); | ||
| assert_eq!(actual, &["program-name", "--msg"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_optional_arg_short() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(option, short = 'm')] | ||
| /// a msg param | ||
| _msg: Option<String>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["-m", "hello"]).unwrap(); | ||
| assert_eq!(actual, &["program-name", "-m"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_optional_arg_long() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(option, long = "my-msg")] | ||
| /// a msg param | ||
| _msg: Option<String>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["--my-msg", "hello"]).unwrap(); | ||
| assert_eq!(actual, &["program-name", "--my-msg"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_two_option_args() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(option)] | ||
| /// a msg param | ||
| msg: String, | ||
| _msg: String, | ||
|
|
||
| #[argh(option)] | ||
| /// a delivery param | ||
| delivery: String, | ||
| _delivery: String, | ||
| } | ||
|
|
||
| let actual = | ||
|
|
@@ -960,11 +988,11 @@ fn redact_arg_values_option_one_optional_args() { | |
| struct Cmd { | ||
| #[argh(option)] | ||
| /// a msg param | ||
| msg: String, | ||
| _msg: String, | ||
|
|
||
| #[argh(option)] | ||
| /// a delivery param | ||
| delivery: Option<String>, | ||
| _delivery: Option<String>, | ||
| } | ||
|
|
||
| let actual = | ||
|
|
@@ -976,14 +1004,32 @@ fn redact_arg_values_option_one_optional_args() { | |
| assert_eq!(actual, &["program-name", "--msg"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_option_repeating() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(option)] | ||
| /// fooey | ||
| _msg: Vec<String>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &[]).unwrap(); | ||
| assert_eq!(actual, &["program-name"]); | ||
|
|
||
| let actual = | ||
| Cmd::redact_arg_values(&["program-name"], &["--msg", "abc", "--msg", "xyz"]).unwrap(); | ||
| assert_eq!(actual, &["program-name", "--msg", "--msg"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_switch() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(switch, short = 'f')] | ||
| /// speed of cmd | ||
| faster: bool, | ||
| _faster: bool, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["--faster"]).unwrap(); | ||
|
|
@@ -998,6 +1044,7 @@ fn redact_arg_values_positional() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[allow(dead_code)] | ||
| #[argh(positional)] | ||
| /// speed of cmd | ||
| speed: u8, | ||
|
|
@@ -1007,14 +1054,28 @@ fn redact_arg_values_positional() { | |
| assert_eq!(actual, &["program-name", "speed"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_positional_arg_name() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional, arg_name = "speed")] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed offline, I have no problem with the implementation of an You changed most (all?) of the fields in your test structs (at least in this commit) to add an underscore to the fields. I'm assuming you did this because you are getting warnings that these fields are This sounds very related to the problems that we've seen in other Rust code bases after rust-lang/rust#85200 landed. Many downstream structs that depended on I'm not sure if that change or some other change broke how I would like to know if you can track down the origin of the change in 1.57 to see if there is a better, internal workaround in the If that's not feasible, and you feel it's OK to just pass the burden down to the users of And if you can do that, is that the only reason to implement an
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I updated these fields to be prefixed with
I don't think we have a great way to do that. The problem we're running into is that all these tests are doing is calling To avoid the warning, we could change the derived Perhaps a better way of doing this would be to get rid of However, I'm not sure how painful this is going to be in practice. In order to trip over this, users would need to have an impl of
Sure, I filed #113 to track this. I think we can implement that in a future PR though.
Yeah there are other use cases for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK cool. Well, if #113 gets implemented, then most of the |
||
| /// speed of cmd | ||
| _speed: u8, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["5"]).unwrap(); | ||
| assert_eq!(actual, &["program-name", "speed"]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn redact_arg_values_positional_repeating() { | ||
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: Vec<u8>, | ||
| _speed: Vec<u8>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["5", "6"]).unwrap(); | ||
|
|
@@ -1026,9 +1087,9 @@ fn redact_arg_values_positional_err() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: u8, | ||
| _speed: u8, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &[]).unwrap_err(); | ||
|
|
@@ -1046,13 +1107,13 @@ fn redact_arg_values_two_positional() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: u8, | ||
| _speed: u8, | ||
|
|
||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "direction")] | ||
| /// direction | ||
| direction: String, | ||
| _direction: String, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["5", "north"]).unwrap(); | ||
|
|
@@ -1064,13 +1125,13 @@ fn redact_arg_values_positional_option() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: u8, | ||
| _speed: u8, | ||
|
|
||
| #[argh(option)] | ||
| /// direction | ||
| direction: String, | ||
| _direction: String, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["5", "--direction", "north"]).unwrap(); | ||
|
|
@@ -1082,13 +1143,13 @@ fn redact_arg_values_positional_optional_option() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: u8, | ||
| _speed: u8, | ||
|
|
||
| #[argh(option)] | ||
| /// direction | ||
| direction: Option<String>, | ||
| _direction: Option<String>, | ||
| } | ||
|
|
||
| let actual = Cmd::redact_arg_values(&["program-name"], &["5"]).unwrap(); | ||
|
|
@@ -1100,13 +1161,13 @@ fn redact_arg_values_subcommand() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: u8, | ||
| _speed: u8, | ||
|
|
||
| #[argh(subcommand)] | ||
| /// means of transportation | ||
| means: MeansSubcommand, | ||
| _means: MeansSubcommand, | ||
| } | ||
|
|
||
| #[derive(FromArgs, Debug)] | ||
|
|
@@ -1124,7 +1185,7 @@ fn redact_arg_values_subcommand() { | |
| struct WalkingSubcommand { | ||
| #[argh(option)] | ||
| /// a song to listen to | ||
| music: String, | ||
| _music: String, | ||
| } | ||
|
|
||
| #[derive(FromArgs, Debug)] | ||
|
|
@@ -1146,13 +1207,13 @@ fn redact_arg_values_subcommand_with_space_in_name() { | |
| #[derive(FromArgs, Debug)] | ||
| /// Short description | ||
| struct Cmd { | ||
| #[argh(positional)] | ||
| #[argh(positional, arg_name = "speed")] | ||
| /// speed of cmd | ||
| speed: u8, | ||
| _speed: u8, | ||
|
|
||
| #[argh(subcommand)] | ||
| /// means of transportation | ||
| means: MeansSubcommand, | ||
| _means: MeansSubcommand, | ||
| } | ||
|
|
||
| #[derive(FromArgs, Debug)] | ||
|
|
@@ -1169,7 +1230,7 @@ fn redact_arg_values_subcommand_with_space_in_name() { | |
| struct WalkingSubcommand { | ||
| #[argh(option)] | ||
| /// a song to listen to | ||
| music: String, | ||
| _music: String, | ||
| } | ||
|
|
||
| #[derive(FromArgs, Debug)] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.