Skip to content

Commit 539ece7

Browse files
authored
test coverage for error messages (#5)
1 parent 9eb1be7 commit 539ece7

File tree

20 files changed

+115
-27
lines changed

20 files changed

+115
-27
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
2424
[dev-dependencies]
2525
assert_cmd = "2.0.10"
2626
rusty-hook = "^0.11.2"
27+
predicates = "3.0.2"
File renamed without changes.

src/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ext::IntoContext;
1+
use error_stack_ext::IntoContext;
22
use ownership::Ownership;
33

44
use crate::project::Project;
@@ -13,7 +13,7 @@ use std::{
1313
};
1414

1515
mod config;
16-
mod ext;
16+
mod error_stack_ext;
1717
mod ownership;
1818
mod project;
1919

@@ -85,7 +85,7 @@ impl Context for Error {}
8585

8686
fn main() -> Result<(), Error> {
8787
install_logger();
88-
print_validation_errors_to_stdout(cli())?;
88+
maybe_print_errors(cli())?;
8989

9090
Ok(())
9191
}
@@ -99,14 +99,13 @@ fn cli() -> Result<(), Error> {
9999

100100
let config_file = File::open(&config_path)
101101
.into_context(Error::Io)
102-
.attach_printable(format!("{}", config_path.to_string_lossy()))?;
102+
.attach_printable(format!("Can't open config file: {}", config_path.to_string_lossy()))?;
103103

104104
let config = serde_yaml::from_reader(config_file).into_context(Error::Io)?;
105105

106106
let ownership = Ownership::build(Project::build(&project_root, &codeowners_file_path, &config).change_context(Error::Io)?);
107-
let command = args.command;
108107

109-
match command {
108+
match args.command {
110109
Command::Validate => ownership.validate().into_context(Error::ValidationFailed)?,
111110
Command::Generate => {
112111
std::fs::write(codeowners_file_path, ownership.generate_file()).into_context(Error::Io)?;
@@ -120,7 +119,7 @@ fn cli() -> Result<(), Error> {
120119
Ok(())
121120
}
122121

123-
fn print_validation_errors_to_stdout(result: Result<(), Error>) -> Result<(), Error> {
122+
fn maybe_print_errors(result: Result<(), Error>) -> Result<(), Error> {
124123
if let Err(error) = result {
125124
if let Some(validation_errors) = error.downcast_ref::<ownership::ValidatorErrors>() {
126125
println!("{}", validation_errors);

src/ownership/validator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ impl Error {
157157
impl Display for Errors {
158158
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
159159
let grouped_errors = self.0.iter().into_group_map_by(|error| error.error_category_message());
160+
let grouped_errors = Vec::from_iter(grouped_errors.iter());
161+
160162
for (error_category_message, errors) in grouped_errors {
161163
write!(f, "\n{}", error_category_message)?;
162164

src/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rayon::prelude::{IntoParallelIterator, ParallelIterator};
1313
use regex::Regex;
1414
use tracing::{debug, instrument};
1515

16-
use crate::{config::Config, ext::IntoContext};
16+
use crate::{config::Config, error_stack_ext::IntoContext};
1717
use glob_match::glob_match;
1818

1919
pub struct Project {
@@ -131,7 +131,7 @@ impl Context for Error {}
131131
impl Project {
132132
#[instrument(level = "debug", skip_all)]
133133
pub fn build(base_path: &Path, codeowners_file_path: &Path, config: &Config) -> Result<Self, Error> {
134-
debug!("scanning project ({})", base_path.to_string_lossy());
134+
debug!(base_path = base_path.to_str(), "scanning project");
135135

136136
let mut owned_file_paths: Vec<PathBuf> = Vec::new();
137137
let mut packages: Vec<Package> = Vec::new();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
owned_globs:
2+
- "**/*.{rb,tsx}"
3+
ruby_package_paths:
4+
- ruby/packages/**/*
5+
javascript_package_paths:
6+
- javascript/packages/**
7+
team_file_glob:
8+
- config/teams/**/*.yml
9+
vendored_gems_path: gems
10+
unowned_globs:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: Payments
2+
github:
3+
team: '@PaymentTeam'
4+
owned_globs:
5+
- ruby/app/payments/**/*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Payroll
2+
github:
3+
team: '@PayrollTeam'
4+
ruby:
5+
owned_gems:
6+
- payroll_calculator
7+
javascript:
8+
owned_packages:
9+
- 'PayrollFlow'

0 commit comments

Comments
 (0)