Skip to content

Commit a1f1987

Browse files
atluftspenserblack
andauthored
Add test info mod rs (#827)
* testing bare git repo error using git-testtools script #700 * after running cargo fmt * refactoring new to call init for testing of bare repo detection * brute force testing of format function * idea for testing formatted output using git-testtools arguments * fix formatting * adding pretty assert and concept of match anything in expected string * fixing windows expected output failures * fixing formatting, eventually I will use a hook * removing color based checking, simple regex now * Update src/info/mod.rs Co-authored-by: Spenser Black <spenserblack01@gmail.com> * Update src/info/mod.rs Co-authored-by: Spenser Black <spenserblack01@gmail.com> * updates to use external file w/ regex in it * trying standard path separator to see if windows ci passes * updates to regex that make it easier to read * test coverage of serializer using json * fix formatting * better assert logic for bare repo and pretty assert to debug CI failure in json * fixing git version in json serializarion * obtains 100% code coverage by manipulating git repo and files parsed * more code coverage, trying to get those last few lines * making use of snapshot name in testing * changing verification to string based test * switching to using inst snapshots * adding snap file needed for previous commit * refactor default into Config object to allow Default construction * better naming on function * removing snap file from ignore * using object serialization in test Co-authored-by: Spenser Black <spenserblack01@gmail.com>
1 parent 5d552fb commit a1f1987

9 files changed

+426
-40
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/target
22
**/*.rs.bk
33
/stage
4-
*.snap
54
/parts
65
/prime
76
.gitignore.swp

Cargo.lock

Lines changed: 142 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ section = "utility"
2424

2525
[dev-dependencies]
2626
git-testtools = "0.9.0"
27+
strip-ansi-escapes = "0.1.1"
28+
pretty_assertions = "1.3.0"
29+
insta = { version = "1.21.0", features = ["json", "redactions"] }
2730

2831
[dependencies]
2932
anyhow = "1.0.66"

src/cli.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,38 @@ pub struct Config {
151151
pub completion: Option<Shell>,
152152
}
153153

154+
impl Default for Config {
155+
fn default() -> Config {
156+
Config {
157+
input: PathBuf::from("."),
158+
ascii_input: Default::default(),
159+
ascii_language: Default::default(),
160+
ascii_colors: Default::default(),
161+
disabled_fields: Default::default(),
162+
image: Default::default(),
163+
image_protocol: Default::default(),
164+
color_resolution: 16,
165+
no_bold: Default::default(),
166+
no_merges: Default::default(),
167+
no_color_palette: Default::default(),
168+
number_of_authors: 3,
169+
exclude: Default::default(),
170+
no_bots: Default::default(),
171+
languages: Default::default(),
172+
package_managers: Default::default(),
173+
output: Default::default(),
174+
true_color: When::Auto,
175+
show_logo: When::Always,
176+
text_colors: Default::default(),
177+
iso_time: Default::default(),
178+
email: Default::default(),
179+
include_hidden: Default::default(),
180+
r#type: vec![LanguageType::Programming, LanguageType::Markup],
181+
completion: Default::default(),
182+
}
183+
}
184+
}
185+
154186
pub fn print_supported_languages() -> Result<()> {
155187
for l in Language::iter() {
156188
println!("{}", l);
@@ -199,13 +231,13 @@ mod test {
199231

200232
#[test]
201233
fn test_default_config() {
202-
let config = get_default_config();
234+
let config: Config = Default::default();
203235
assert_eq!(config, Config::parse_from(&["onefetch"]))
204236
}
205237

206238
#[test]
207239
fn test_custom_config() {
208-
let mut config = get_default_config();
240+
let mut config: Config = Default::default();
209241
config.number_of_authors = 4;
210242
config.input = PathBuf::from("/tmp/folder");
211243
config.no_merges = true;
@@ -255,36 +287,6 @@ mod test {
255287
fn test_config_with_text_colors_but_out_of_bounds() {
256288
assert!(Config::try_parse_from(&["onefetch", "--text-colors", "17"]).is_err())
257289
}
258-
259-
fn get_default_config() -> Config {
260-
Config {
261-
input: PathBuf::from("."),
262-
ascii_input: Default::default(),
263-
ascii_language: Default::default(),
264-
ascii_colors: Default::default(),
265-
disabled_fields: Default::default(),
266-
image: Default::default(),
267-
image_protocol: Default::default(),
268-
color_resolution: 16,
269-
no_bold: Default::default(),
270-
no_merges: Default::default(),
271-
no_color_palette: Default::default(),
272-
number_of_authors: 3,
273-
exclude: Default::default(),
274-
no_bots: Default::default(),
275-
languages: Default::default(),
276-
package_managers: Default::default(),
277-
output: Default::default(),
278-
true_color: When::Auto,
279-
show_logo: When::Always,
280-
text_colors: Default::default(),
281-
iso_time: Default::default(),
282-
email: Default::default(),
283-
include_hidden: Default::default(),
284-
r#type: vec![LanguageType::Programming, LanguageType::Markup],
285-
completion: Default::default(),
286-
}
287-
}
288290
}
289291

290292
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)