-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I tried splitting out the tests so that changes in the tests wouldn't trigger recompilation of the tested module, but that was an overoptimization. I seem to recall making this choice from matklad's excellent One Hundred Thousand Lines of Rust [1] series, but I can't find it again, and I've come to not liking having them split into different modules. [1] https://matklad.github.io/2021/09/05/Rust100k.html
- Loading branch information
Showing
11 changed files
with
217 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,113 @@ pub fn write_config(data_dir: &Path, config: &Config) -> eyre::Result<()> { | |
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::HashMap; | ||
use std::path::PathBuf; | ||
|
||
use herostratus_tests::fixtures::config::empty; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn default_config_toml_contents() { | ||
let default = Config::default(); | ||
let contents = serialize_config(&default).unwrap(); | ||
let expected = "[repositories]\n"; | ||
assert_eq!(contents, expected); | ||
} | ||
|
||
#[test] | ||
fn read_write_config() { | ||
let mut repositories = HashMap::new(); | ||
let config = RepositoryConfig { | ||
path: PathBuf::from("git/Notgnoshi/herostratus"), | ||
branch: None, | ||
url: String::from("[email protected]:Notgnoshi/herostratus.git"), | ||
..Default::default() | ||
}; | ||
repositories.insert(String::from("herostratus"), config); | ||
let config = Config { | ||
repositories, | ||
..Default::default() | ||
}; | ||
|
||
let fixture = empty().unwrap(); | ||
write_config(&fixture.data_dir, &config).unwrap(); | ||
|
||
let contents = std::fs::read_to_string(config_path(&fixture.data_dir)).unwrap(); | ||
let expected = "[repositories.herostratus]\n\ | ||
path = \"git/Notgnoshi/herostratus\"\n\ | ||
url = \"[email protected]:Notgnoshi/herostratus.git\"\n\ | ||
"; | ||
assert_eq!(contents, expected); | ||
|
||
let read_config = read_config(&fixture.data_dir).unwrap(); | ||
assert_eq!(read_config, config); | ||
} | ||
|
||
#[test] | ||
fn generates_default_config_if_missing() { | ||
let fixture = empty().unwrap(); | ||
let config_file = config_path(&fixture.data_dir); | ||
assert!(!config_file.exists()); | ||
|
||
let config = read_config(&fixture.data_dir).unwrap(); | ||
let default_config = Config::default(); | ||
assert_eq!(config, default_config); | ||
} | ||
|
||
#[test] | ||
fn config_exclude_rules() { | ||
let config_toml = "[repositories.herostratus]\n\ | ||
path = \"git/Notgnoshi/herostratus\"\n\ | ||
url = \"[email protected]:Notgnoshi/herostratus.git\"\n\ | ||
[rules]\n\ | ||
exclude = [\"H4-non-unicode\"]\n\ | ||
"; | ||
|
||
let config = deserialize_config(config_toml).unwrap(); | ||
assert_eq!(config.rules.unwrap().exclude.unwrap(), ["H4-non-unicode"]); | ||
} | ||
|
||
#[test] | ||
fn rule_specific_config() { | ||
let config_toml = "[repositories.herostratus]\n\ | ||
path = \"git/Notgnoshi/herostratus\"\n\ | ||
url = \"[email protected]:Notgnoshi/herostratus.git\"\n\ | ||
[rules]\n\ | ||
h2_shortest_subject_line.length_threshold = 80\n\ | ||
"; | ||
|
||
let config = deserialize_config(config_toml).unwrap(); | ||
assert_eq!( | ||
config | ||
.rules | ||
.unwrap() | ||
.h2_shortest_subject_line | ||
.unwrap() | ||
.length_threshold, | ||
80 | ||
); | ||
|
||
let config_toml = "[repositories.herostratus]\n\ | ||
path = \"git/Notgnoshi/herostratus\"\n\ | ||
url = \"[email protected]:Notgnoshi/herostratus.git\"\n\ | ||
[rules.h2_shortest_subject_line]\n\ | ||
length_threshold = 80\n\ | ||
"; | ||
|
||
let config = deserialize_config(config_toml).unwrap(); | ||
assert_eq!( | ||
config | ||
.rules | ||
.unwrap() | ||
.h2_shortest_subject_line | ||
.unwrap() | ||
.length_threshold, | ||
80 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.