|
1 | 1 | use crate::argv::models::{ArgvOutcome, Value}; |
2 | 2 | use crate::argv::tests::helpers::{parse, strings}; |
3 | | -use crate::argv::tests::test_types::{ExitTestCase, ParsedValueTestCase}; |
| 3 | +use crate::argv::tests::test_types::{ExitTestCase, HelpTextTestCase, ParsedValueTestCase}; |
4 | 4 |
|
5 | 5 | #[test] |
6 | 6 | fn given_accepted_arguments_when_parsing_then_attributes_hold_the_parsed_values() { |
@@ -29,6 +29,12 @@ fn given_accepted_arguments_when_parsing_then_attributes_hold_the_parsed_values( |
29 | 29 | attribute: "dbt_args", |
30 | 30 | expected_value: strings(&["--", "--no-color"]), |
31 | 31 | }, |
| 32 | + ParsedValueTestCase { |
| 33 | + description: "clone still accepts the hidden --no-sql-analysis flag", |
| 34 | + argv: &["clone", "--from", "prod", "--no-sql-analysis"], |
| 35 | + attribute: "no_sql_validation", |
| 36 | + expected_value: Value::Bool(true), |
| 37 | + }, |
32 | 38 | ParsedValueTestCase { |
33 | 39 | description: "a nested sub-command's dest is set", |
34 | 40 | argv: &["contract", "diff", "--from", "prod"], |
@@ -100,3 +106,45 @@ fn given_help_version_or_rejected_arguments_when_parsing_then_exits_after_writin |
100 | 106 | ); |
101 | 107 | } |
102 | 108 | } |
| 109 | + |
| 110 | +#[test] |
| 111 | +fn given_command_help_when_parsing_then_hidden_options_are_left_out() { |
| 112 | + let test_cases = [ |
| 113 | + HelpTextTestCase { |
| 114 | + description: "clone help omits the no-op SQL analysis flag", |
| 115 | + argv: &["clone", "--help"], |
| 116 | + expected_present: &["--from FROM_TARGET", "--select"], |
| 117 | + expected_absent: &["--no-sql-analysis", "--no-sql-validation"], |
| 118 | + }, |
| 119 | + HelpTextTestCase { |
| 120 | + description: "build help keeps the SQL analysis flag", |
| 121 | + argv: &["build", "--help"], |
| 122 | + expected_present: &["--no-sql-analysis"], |
| 123 | + expected_absent: &[], |
| 124 | + }, |
| 125 | + ]; |
| 126 | + |
| 127 | + for test_case in test_cases { |
| 128 | + let outcome: ArgvOutcome = parse(test_case.argv); |
| 129 | + let help: String = outcome |
| 130 | + .writes |
| 131 | + .iter() |
| 132 | + .map(|(_, text)| text.as_str()) |
| 133 | + .collect(); |
| 134 | + let present: Vec<&str> = test_case |
| 135 | + .expected_present |
| 136 | + .iter() |
| 137 | + .copied() |
| 138 | + .filter(|fragment| help.contains(fragment)) |
| 139 | + .collect(); |
| 140 | + let absent: Vec<&str> = test_case |
| 141 | + .expected_absent |
| 142 | + .iter() |
| 143 | + .copied() |
| 144 | + .filter(|fragment| !help.contains(fragment)) |
| 145 | + .collect(); |
| 146 | + assert_eq!(outcome.parsed, Err(0), "{}", test_case.description); |
| 147 | + assert_eq!(present, test_case.expected_present, "{help}"); |
| 148 | + assert_eq!(absent, test_case.expected_absent, "{help}"); |
| 149 | + } |
| 150 | +} |
0 commit comments