Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fixtures/configs/lychee.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# this is an invalid toml config file with the default config file name
{}
18 changes: 14 additions & 4 deletions lychee-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,20 @@ fn load_config() -> Result<LycheeOptions> {
}
} else {
// If no config file was explicitly provided, we try to load the default
// config file from the current directory, but it's not an error if it
// doesn't exist.
if let Ok(c) = Config::load_from_file(&PathBuf::from(LYCHEE_CONFIG_FILE)) {
opts.config.merge(c);
// config file from the current directory if the file exits. This will
// raise an error if the file is invalid, just like the explicit provided
// config file.
let default_config = PathBuf::from(LYCHEE_CONFIG_FILE);
if default_config.is_file() {
match Config::load_from_file(&default_config) {
Ok(c) => opts.config.merge(c),
Err(e) => {
bail!(
"Cannot load default configuration file `{}`: {e:?}",
default_config.display()
);
}
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions lychee-bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,19 @@ mod cli {
Ok(())
}

#[test]
fn test_invalid_default_config() -> Result<()> {
let test_path = fixtures_path().join("configs");
let mut cmd = main_command();
cmd.current_dir(test_path)
.arg(".")
.assert()
.failure()
.stderr(contains("Cannot load default configuration file"));

Ok(())
}

#[tokio::test]
async fn test_include_mail_config() -> Result<()> {
let test_mail_address = "mailto:hello-test@testingabc.io";
Expand Down