Skip to content

Commit

Permalink
Add test info mod rs (#827)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update src/info/mod.rs

Co-authored-by: Spenser Black <[email protected]>

* 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 <[email protected]>
  • Loading branch information
atluft and spenserblack authored Oct 29, 2022
1 parent 5d552fb commit a1f1987
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 40 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/target
**/*.rs.bk
/stage
*.snap
/parts
/prime
.gitignore.swp
Expand Down
145 changes: 142 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ section = "utility"

[dev-dependencies]
git-testtools = "0.9.0"
strip-ansi-escapes = "0.1.1"
pretty_assertions = "1.3.0"
insta = { version = "1.21.0", features = ["json", "redactions"] }

[dependencies]
anyhow = "1.0.66"
Expand Down
66 changes: 34 additions & 32 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ pub struct Config {
pub completion: Option<Shell>,
}

impl Default for Config {
fn default() -> Config {
Config {
input: PathBuf::from("."),
ascii_input: Default::default(),
ascii_language: Default::default(),
ascii_colors: Default::default(),
disabled_fields: Default::default(),
image: Default::default(),
image_protocol: Default::default(),
color_resolution: 16,
no_bold: Default::default(),
no_merges: Default::default(),
no_color_palette: Default::default(),
number_of_authors: 3,
exclude: Default::default(),
no_bots: Default::default(),
languages: Default::default(),
package_managers: Default::default(),
output: Default::default(),
true_color: When::Auto,
show_logo: When::Always,
text_colors: Default::default(),
iso_time: Default::default(),
email: Default::default(),
include_hidden: Default::default(),
r#type: vec![LanguageType::Programming, LanguageType::Markup],
completion: Default::default(),
}
}
}

pub fn print_supported_languages() -> Result<()> {
for l in Language::iter() {
println!("{}", l);
Expand Down Expand Up @@ -199,13 +231,13 @@ mod test {

#[test]
fn test_default_config() {
let config = get_default_config();
let config: Config = Default::default();
assert_eq!(config, Config::parse_from(&["onefetch"]))
}

#[test]
fn test_custom_config() {
let mut config = get_default_config();
let mut config: Config = Default::default();
config.number_of_authors = 4;
config.input = PathBuf::from("/tmp/folder");
config.no_merges = true;
Expand Down Expand Up @@ -255,36 +287,6 @@ mod test {
fn test_config_with_text_colors_but_out_of_bounds() {
assert!(Config::try_parse_from(&["onefetch", "--text-colors", "17"]).is_err())
}

fn get_default_config() -> Config {
Config {
input: PathBuf::from("."),
ascii_input: Default::default(),
ascii_language: Default::default(),
ascii_colors: Default::default(),
disabled_fields: Default::default(),
image: Default::default(),
image_protocol: Default::default(),
color_resolution: 16,
no_bold: Default::default(),
no_merges: Default::default(),
no_color_palette: Default::default(),
number_of_authors: 3,
exclude: Default::default(),
no_bots: Default::default(),
languages: Default::default(),
package_managers: Default::default(),
output: Default::default(),
true_color: When::Auto,
show_logo: When::Always,
text_colors: Default::default(),
iso_time: Default::default(),
email: Default::default(),
include_hidden: Default::default(),
r#type: vec![LanguageType::Programming, LanguageType::Markup],
completion: Default::default(),
}
}
}

#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit a1f1987

Please sign in to comment.