Run clippy and tests with --all-targets --all-features

This commit is contained in:
Nick Groenen 2024-08-03 13:17:45 +02:00
parent fc0221e5db
commit bd1220028b
No known key found for this signature in database
GPG Key ID: 4F0AD019928AE098
7 changed files with 39 additions and 39 deletions

View File

@ -20,8 +20,8 @@ jobs:
matrix:
job:
- cargo fmt --all -- --check
- cargo test
- cargo clippy -- -D warnings
- cargo test --all-targets --all-features
- cargo clippy --all-targets --all-features -- -D warning
fail-fast: false
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

View File

@ -20,13 +20,13 @@ repos:
files: \.rs$
- id: tests
name: Run tests
entry: cargo test
entry: cargo test --all-targets --all-features
language: system
files: \.rs$
pass_filenames: false
- id: clippy
name: Check clippy lints
entry: cargo clippy -- -D warnings
entry: cargo clippy --all-targets --all-features -- -D warnings
language: system
files: \.rs$
pass_filenames: false

View File

@ -88,10 +88,7 @@ mod tests {
#[test]
fn nonempty_frontmatter_to_str() {
let mut frontmatter = Frontmatter::new();
frontmatter.insert(
Value::String("foo".to_string()),
Value::String("bar".to_string()),
);
frontmatter.insert(Value::String("foo".into()), Value::String("bar".into()));
assert_eq!(
frontmatter_to_str(&frontmatter).unwrap(),
format!("---\nfoo: bar\n---\n")

View File

@ -912,6 +912,7 @@ mod tests {
}
#[test]
#[allow(clippy::unicode_not_nfc)]
fn encodings() {
// Standard "Latin Small Letter A with Diaeresis" (U+00E4)
// Encoded in UTF-8 as two bytes: 0xC3 0xA4

View File

@ -54,8 +54,8 @@ fn filter_by_tags_(
#[test]
fn test_filter_tags() {
let tags = vec![
Value::String("skip".to_string()),
Value::String("publish".to_string()),
Value::String("skip".into()),
Value::String("publish".into()),
];
let empty_tags = vec![];
assert_eq!(
@ -69,37 +69,37 @@ fn test_filter_tags() {
"When no exclusion & inclusion are specified, files with tags are included"
);
assert_eq!(
filter_by_tags_(&tags, &["exclude".to_string()], &[]),
filter_by_tags_(&tags, &["exclude".into()], &[]),
PostprocessorResult::Continue,
"When exclusion tags don't match files with tags are included"
);
assert_eq!(
filter_by_tags_(&empty_tags, &["exclude".to_string()], &[]),
filter_by_tags_(&empty_tags, &["exclude".into()], &[]),
PostprocessorResult::Continue,
"When exclusion tags don't match files without tags are included"
);
assert_eq!(
filter_by_tags_(&tags, &[], &["publish".to_string()]),
filter_by_tags_(&tags, &[], &["publish".into()]),
PostprocessorResult::Continue,
"When exclusion tags don't match files with tags are included"
);
assert_eq!(
filter_by_tags_(&empty_tags, &[], &["include".to_string()]),
filter_by_tags_(&empty_tags, &[], &["include".into()]),
PostprocessorResult::StopAndSkipNote,
"When inclusion tags are specified files without tags are excluded"
);
assert_eq!(
filter_by_tags_(&tags, &[], &["include".to_string()]),
filter_by_tags_(&tags, &[], &["include".into()]),
PostprocessorResult::StopAndSkipNote,
"When exclusion tags don't match files with tags are exluded"
);
assert_eq!(
filter_by_tags_(&tags, &["skip".to_string()], &["skip".to_string()]),
filter_by_tags_(&tags, &["skip".into()], &["skip".into()]),
PostprocessorResult::StopAndSkipNote,
"When both inclusion and exclusion tags are the same exclusion wins"
);
assert_eq!(
filter_by_tags_(&tags, &["skip".to_string()], &["publish".to_string()]),
filter_by_tags_(&tags, &["skip".into()], &["publish".into()]),
PostprocessorResult::StopAndSkipNote,
"When both inclusion and exclusion tags match exclusion wins"
);

View File

@ -1,3 +1,5 @@
#![allow(clippy::shadow_unrelated)]
use obsidian_export::{ExportError, Exporter, FrontmatterStrategy};
use pretty_assertions::assert_eq;
use std::fs::{create_dir, read_to_string, set_permissions, File, Permissions};
@ -237,7 +239,7 @@ fn test_not_existing_source() {
.unwrap_err();
match err {
ExportError::PathDoesNotExist { path: _ } => {}
ExportError::PathDoesNotExist { .. } => {}
_ => panic!("Wrong error variant: {:?}", err),
}
}
@ -254,7 +256,7 @@ fn test_not_existing_destination_with_source_dir() {
.unwrap_err();
match err {
ExportError::PathDoesNotExist { path: _ } => {}
ExportError::PathDoesNotExist { .. } => {}
_ => panic!("Wrong error variant: {:?}", err),
}
}
@ -274,7 +276,7 @@ fn test_not_existing_destination_with_source_file() {
.unwrap_err();
match err {
ExportError::PathDoesNotExist { path: _ } => {}
ExportError::PathDoesNotExist { .. } => {}
_ => panic!("Wrong error variant: {:?}", err),
}
}
@ -287,12 +289,12 @@ fn test_source_no_permissions() {
let dest = tmp_dir.path().to_path_buf().join("dest.md");
let mut file = File::create(&src).unwrap();
file.write_all("Foo".as_bytes()).unwrap();
file.write_all(b"Foo").unwrap();
set_permissions(&src, Permissions::from_mode(0o000)).unwrap();
match Exporter::new(src, dest).run().unwrap_err() {
ExportError::FileExportError { path: _, source } => match *source {
ExportError::ReadError { path: _, source: _ } => {}
ExportError::FileExportError { source, .. } => match *source {
ExportError::ReadError { .. } => {}
_ => panic!("Wrong error variant for source, got: {:?}", source),
},
err => panic!("Wrong error variant: {:?}", err),
@ -307,14 +309,14 @@ fn test_dest_no_permissions() {
let dest = tmp_dir.path().to_path_buf().join("dest");
let mut file = File::create(&src).unwrap();
file.write_all("Foo".as_bytes()).unwrap();
file.write_all(b"Foo").unwrap();
create_dir(&dest).unwrap();
set_permissions(&dest, Permissions::from_mode(0o555)).unwrap();
match Exporter::new(src, dest).run().unwrap_err() {
ExportError::FileExportError { path: _, source } => match *source {
ExportError::WriteError { path: _, source: _ } => {}
ExportError::FileExportError { source, .. } => match *source {
ExportError::WriteError { .. } => {}
_ => panic!("Wrong error variant for source, got: {:?}", source),
},
err => panic!("Wrong error variant: {:?}", err),
@ -333,7 +335,7 @@ fn test_infinite_recursion() {
.unwrap_err();
match err {
ExportError::FileExportError { path: _, source } => match *source {
ExportError::FileExportError { source, .. } => match *source {
ExportError::RecursionLimitExceeded { .. } => {}
_ => panic!("Wrong error variant for source, got: {:?}", source),
},

View File

@ -11,7 +11,7 @@ use tempfile::TempDir;
use walkdir::WalkDir;
/// This postprocessor replaces any instance of "foo" with "bar" in the note body.
fn foo_to_bar(_ctx: &mut Context, events: &mut MarkdownEvents) -> PostprocessorResult {
fn foo_to_bar(_ctx: &mut Context, events: &mut MarkdownEvents<'_>) -> PostprocessorResult {
for event in events.iter_mut() {
if let Event::Text(text) = event {
*event = Event::Text(CowStr::from(text.replace("foo", "bar")));
@ -21,11 +21,9 @@ fn foo_to_bar(_ctx: &mut Context, events: &mut MarkdownEvents) -> PostprocessorR
}
/// This postprocessor appends "bar: baz" to frontmatter.
fn append_frontmatter(ctx: &mut Context, _events: &mut MarkdownEvents) -> PostprocessorResult {
ctx.frontmatter.insert(
Value::String("bar".to_string()),
Value::String("baz".to_string()),
);
fn append_frontmatter(ctx: &mut Context, _events: &mut MarkdownEvents<'_>) -> PostprocessorResult {
ctx.frontmatter
.insert(Value::String("bar".into()), Value::String("baz".into()));
PostprocessorResult::Continue
}
@ -113,6 +111,7 @@ fn test_postprocessor_change_destination() {
// error[E0597]: `parents` does not live long enough
// cast requires that `parents` is borrowed for `'static`
#[test]
#[allow(clippy::significant_drop_tightening)]
fn test_postprocessor_stateful_callback() {
let tmp_dir = TempDir::new().expect("failed to make tempdir");
let mut exporter = Exporter::new(
@ -120,8 +119,8 @@ fn test_postprocessor_stateful_callback() {
tmp_dir.path().to_path_buf(),
);
let parents: Mutex<HashSet<PathBuf>> = Default::default();
let callback = |ctx: &mut Context, _mdevents: &mut MarkdownEvents| -> PostprocessorResult {
let parents: Mutex<HashSet<PathBuf>> = Mutex::default();
let callback = |ctx: &mut Context, _mdevents: &mut MarkdownEvents<'_>| -> PostprocessorResult {
parents
.lock()
.unwrap()
@ -187,6 +186,7 @@ fn test_embed_postprocessors_stop_and_skip() {
// correct. Primarily, this means the frontmatter should reflect that of the note being embedded as
// opposed to the frontmatter of the root note.
#[test]
#[allow(clippy::manual_assert)]
fn test_embed_postprocessors_context() {
let tmp_dir = TempDir::new().expect("failed to make tempdir");
let mut exporter = Exporter::new(
@ -200,7 +200,7 @@ fn test_embed_postprocessors_context() {
}
let is_root_note = ctx
.frontmatter
.get(&Value::String("is_root_note".to_string()))
.get(&Value::String("is_root_note".into()))
.unwrap();
if is_root_note != &Value::Bool(true) {
// NOTE: Test failure may not give output consistently because the test binary affects
@ -216,7 +216,7 @@ fn test_embed_postprocessors_context() {
exporter.add_embed_postprocessor(&|ctx, _mdevents| {
let is_root_note = ctx
.frontmatter
.get(&Value::String("is_root_note".to_string()))
.get(&Value::String("is_root_note".into()))
.unwrap();
if is_root_note == &Value::Bool(true) {
// NOTE: Test failure may not give output consistently because the test binary affects
@ -257,8 +257,8 @@ fn test_filter_by_tags() {
tmp_dir.path().to_path_buf(),
);
let filter_by_tags = filter_by_tags(
vec!["private".to_string(), "no-export".to_string()],
vec!["export".to_string()],
vec!["private".into(), "no-export".into()],
vec!["export".into()],
);
exporter.add_postprocessor(&filter_by_tags);
exporter.run().unwrap();