Run clippy and tests with --all-targets --all-features
This commit is contained in:
parent
fc0221e5db
commit
bd1220028b
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -20,8 +20,8 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
job:
|
job:
|
||||||
- cargo fmt --all -- --check
|
- cargo fmt --all -- --check
|
||||||
- cargo test
|
- cargo test --all-targets --all-features
|
||||||
- cargo clippy -- -D warnings
|
- cargo clippy --all-targets --all-features -- -D warning
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
|
||||||
|
@ -20,13 +20,13 @@ repos:
|
|||||||
files: \.rs$
|
files: \.rs$
|
||||||
- id: tests
|
- id: tests
|
||||||
name: Run tests
|
name: Run tests
|
||||||
entry: cargo test
|
entry: cargo test --all-targets --all-features
|
||||||
language: system
|
language: system
|
||||||
files: \.rs$
|
files: \.rs$
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
- id: clippy
|
- id: clippy
|
||||||
name: Check clippy lints
|
name: Check clippy lints
|
||||||
entry: cargo clippy -- -D warnings
|
entry: cargo clippy --all-targets --all-features -- -D warnings
|
||||||
language: system
|
language: system
|
||||||
files: \.rs$
|
files: \.rs$
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
@ -88,10 +88,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn nonempty_frontmatter_to_str() {
|
fn nonempty_frontmatter_to_str() {
|
||||||
let mut frontmatter = Frontmatter::new();
|
let mut frontmatter = Frontmatter::new();
|
||||||
frontmatter.insert(
|
frontmatter.insert(Value::String("foo".into()), Value::String("bar".into()));
|
||||||
Value::String("foo".to_string()),
|
|
||||||
Value::String("bar".to_string()),
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
frontmatter_to_str(&frontmatter).unwrap(),
|
frontmatter_to_str(&frontmatter).unwrap(),
|
||||||
format!("---\nfoo: bar\n---\n")
|
format!("---\nfoo: bar\n---\n")
|
||||||
|
@ -912,6 +912,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::unicode_not_nfc)]
|
||||||
fn encodings() {
|
fn encodings() {
|
||||||
// Standard "Latin Small Letter A with Diaeresis" (U+00E4)
|
// Standard "Latin Small Letter A with Diaeresis" (U+00E4)
|
||||||
// Encoded in UTF-8 as two bytes: 0xC3 0xA4
|
// Encoded in UTF-8 as two bytes: 0xC3 0xA4
|
||||||
|
@ -54,8 +54,8 @@ fn filter_by_tags_(
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_filter_tags() {
|
fn test_filter_tags() {
|
||||||
let tags = vec![
|
let tags = vec![
|
||||||
Value::String("skip".to_string()),
|
Value::String("skip".into()),
|
||||||
Value::String("publish".to_string()),
|
Value::String("publish".into()),
|
||||||
];
|
];
|
||||||
let empty_tags = vec![];
|
let empty_tags = vec![];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -69,37 +69,37 @@ fn test_filter_tags() {
|
|||||||
"When no exclusion & inclusion are specified, files with tags are included"
|
"When no exclusion & inclusion are specified, files with tags are included"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&tags, &["exclude".to_string()], &[]),
|
filter_by_tags_(&tags, &["exclude".into()], &[]),
|
||||||
PostprocessorResult::Continue,
|
PostprocessorResult::Continue,
|
||||||
"When exclusion tags don't match files with tags are included"
|
"When exclusion tags don't match files with tags are included"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&empty_tags, &["exclude".to_string()], &[]),
|
filter_by_tags_(&empty_tags, &["exclude".into()], &[]),
|
||||||
PostprocessorResult::Continue,
|
PostprocessorResult::Continue,
|
||||||
"When exclusion tags don't match files without tags are included"
|
"When exclusion tags don't match files without tags are included"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&tags, &[], &["publish".to_string()]),
|
filter_by_tags_(&tags, &[], &["publish".into()]),
|
||||||
PostprocessorResult::Continue,
|
PostprocessorResult::Continue,
|
||||||
"When exclusion tags don't match files with tags are included"
|
"When exclusion tags don't match files with tags are included"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&empty_tags, &[], &["include".to_string()]),
|
filter_by_tags_(&empty_tags, &[], &["include".into()]),
|
||||||
PostprocessorResult::StopAndSkipNote,
|
PostprocessorResult::StopAndSkipNote,
|
||||||
"When inclusion tags are specified files without tags are excluded"
|
"When inclusion tags are specified files without tags are excluded"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&tags, &[], &["include".to_string()]),
|
filter_by_tags_(&tags, &[], &["include".into()]),
|
||||||
PostprocessorResult::StopAndSkipNote,
|
PostprocessorResult::StopAndSkipNote,
|
||||||
"When exclusion tags don't match files with tags are exluded"
|
"When exclusion tags don't match files with tags are exluded"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&tags, &["skip".to_string()], &["skip".to_string()]),
|
filter_by_tags_(&tags, &["skip".into()], &["skip".into()]),
|
||||||
PostprocessorResult::StopAndSkipNote,
|
PostprocessorResult::StopAndSkipNote,
|
||||||
"When both inclusion and exclusion tags are the same exclusion wins"
|
"When both inclusion and exclusion tags are the same exclusion wins"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_by_tags_(&tags, &["skip".to_string()], &["publish".to_string()]),
|
filter_by_tags_(&tags, &["skip".into()], &["publish".into()]),
|
||||||
PostprocessorResult::StopAndSkipNote,
|
PostprocessorResult::StopAndSkipNote,
|
||||||
"When both inclusion and exclusion tags match exclusion wins"
|
"When both inclusion and exclusion tags match exclusion wins"
|
||||||
);
|
);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::shadow_unrelated)]
|
||||||
|
|
||||||
use obsidian_export::{ExportError, Exporter, FrontmatterStrategy};
|
use obsidian_export::{ExportError, Exporter, FrontmatterStrategy};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use std::fs::{create_dir, read_to_string, set_permissions, File, Permissions};
|
use std::fs::{create_dir, read_to_string, set_permissions, File, Permissions};
|
||||||
@ -237,7 +239,7 @@ fn test_not_existing_source() {
|
|||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
ExportError::PathDoesNotExist { path: _ } => {}
|
ExportError::PathDoesNotExist { .. } => {}
|
||||||
_ => panic!("Wrong error variant: {:?}", err),
|
_ => panic!("Wrong error variant: {:?}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,7 +256,7 @@ fn test_not_existing_destination_with_source_dir() {
|
|||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
ExportError::PathDoesNotExist { path: _ } => {}
|
ExportError::PathDoesNotExist { .. } => {}
|
||||||
_ => panic!("Wrong error variant: {:?}", err),
|
_ => panic!("Wrong error variant: {:?}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,7 +276,7 @@ fn test_not_existing_destination_with_source_file() {
|
|||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
ExportError::PathDoesNotExist { path: _ } => {}
|
ExportError::PathDoesNotExist { .. } => {}
|
||||||
_ => panic!("Wrong error variant: {:?}", err),
|
_ => 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 dest = tmp_dir.path().to_path_buf().join("dest.md");
|
||||||
|
|
||||||
let mut file = File::create(&src).unwrap();
|
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();
|
set_permissions(&src, Permissions::from_mode(0o000)).unwrap();
|
||||||
|
|
||||||
match Exporter::new(src, dest).run().unwrap_err() {
|
match Exporter::new(src, dest).run().unwrap_err() {
|
||||||
ExportError::FileExportError { path: _, source } => match *source {
|
ExportError::FileExportError { source, .. } => match *source {
|
||||||
ExportError::ReadError { path: _, source: _ } => {}
|
ExportError::ReadError { .. } => {}
|
||||||
_ => panic!("Wrong error variant for source, got: {:?}", source),
|
_ => panic!("Wrong error variant for source, got: {:?}", source),
|
||||||
},
|
},
|
||||||
err => panic!("Wrong error variant: {:?}", err),
|
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 dest = tmp_dir.path().to_path_buf().join("dest");
|
||||||
|
|
||||||
let mut file = File::create(&src).unwrap();
|
let mut file = File::create(&src).unwrap();
|
||||||
file.write_all("Foo".as_bytes()).unwrap();
|
file.write_all(b"Foo").unwrap();
|
||||||
|
|
||||||
create_dir(&dest).unwrap();
|
create_dir(&dest).unwrap();
|
||||||
set_permissions(&dest, Permissions::from_mode(0o555)).unwrap();
|
set_permissions(&dest, Permissions::from_mode(0o555)).unwrap();
|
||||||
|
|
||||||
match Exporter::new(src, dest).run().unwrap_err() {
|
match Exporter::new(src, dest).run().unwrap_err() {
|
||||||
ExportError::FileExportError { path: _, source } => match *source {
|
ExportError::FileExportError { source, .. } => match *source {
|
||||||
ExportError::WriteError { path: _, source: _ } => {}
|
ExportError::WriteError { .. } => {}
|
||||||
_ => panic!("Wrong error variant for source, got: {:?}", source),
|
_ => panic!("Wrong error variant for source, got: {:?}", source),
|
||||||
},
|
},
|
||||||
err => panic!("Wrong error variant: {:?}", err),
|
err => panic!("Wrong error variant: {:?}", err),
|
||||||
@ -333,7 +335,7 @@ fn test_infinite_recursion() {
|
|||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
ExportError::FileExportError { path: _, source } => match *source {
|
ExportError::FileExportError { source, .. } => match *source {
|
||||||
ExportError::RecursionLimitExceeded { .. } => {}
|
ExportError::RecursionLimitExceeded { .. } => {}
|
||||||
_ => panic!("Wrong error variant for source, got: {:?}", source),
|
_ => panic!("Wrong error variant for source, got: {:?}", source),
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ use tempfile::TempDir;
|
|||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
/// This postprocessor replaces any instance of "foo" with "bar" in the note body.
|
/// 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() {
|
for event in events.iter_mut() {
|
||||||
if let Event::Text(text) = event {
|
if let Event::Text(text) = event {
|
||||||
*event = Event::Text(CowStr::from(text.replace("foo", "bar")));
|
*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.
|
/// This postprocessor appends "bar: baz" to frontmatter.
|
||||||
fn append_frontmatter(ctx: &mut Context, _events: &mut MarkdownEvents) -> PostprocessorResult {
|
fn append_frontmatter(ctx: &mut Context, _events: &mut MarkdownEvents<'_>) -> PostprocessorResult {
|
||||||
ctx.frontmatter.insert(
|
ctx.frontmatter
|
||||||
Value::String("bar".to_string()),
|
.insert(Value::String("bar".into()), Value::String("baz".into()));
|
||||||
Value::String("baz".to_string()),
|
|
||||||
);
|
|
||||||
PostprocessorResult::Continue
|
PostprocessorResult::Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +111,7 @@ fn test_postprocessor_change_destination() {
|
|||||||
// error[E0597]: `parents` does not live long enough
|
// error[E0597]: `parents` does not live long enough
|
||||||
// cast requires that `parents` is borrowed for `'static`
|
// cast requires that `parents` is borrowed for `'static`
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::significant_drop_tightening)]
|
||||||
fn test_postprocessor_stateful_callback() {
|
fn test_postprocessor_stateful_callback() {
|
||||||
let tmp_dir = TempDir::new().expect("failed to make tempdir");
|
let tmp_dir = TempDir::new().expect("failed to make tempdir");
|
||||||
let mut exporter = Exporter::new(
|
let mut exporter = Exporter::new(
|
||||||
@ -120,8 +119,8 @@ fn test_postprocessor_stateful_callback() {
|
|||||||
tmp_dir.path().to_path_buf(),
|
tmp_dir.path().to_path_buf(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let parents: Mutex<HashSet<PathBuf>> = Default::default();
|
let parents: Mutex<HashSet<PathBuf>> = Mutex::default();
|
||||||
let callback = |ctx: &mut Context, _mdevents: &mut MarkdownEvents| -> PostprocessorResult {
|
let callback = |ctx: &mut Context, _mdevents: &mut MarkdownEvents<'_>| -> PostprocessorResult {
|
||||||
parents
|
parents
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.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
|
// correct. Primarily, this means the frontmatter should reflect that of the note being embedded as
|
||||||
// opposed to the frontmatter of the root note.
|
// opposed to the frontmatter of the root note.
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::manual_assert)]
|
||||||
fn test_embed_postprocessors_context() {
|
fn test_embed_postprocessors_context() {
|
||||||
let tmp_dir = TempDir::new().expect("failed to make tempdir");
|
let tmp_dir = TempDir::new().expect("failed to make tempdir");
|
||||||
let mut exporter = Exporter::new(
|
let mut exporter = Exporter::new(
|
||||||
@ -200,7 +200,7 @@ fn test_embed_postprocessors_context() {
|
|||||||
}
|
}
|
||||||
let is_root_note = ctx
|
let is_root_note = ctx
|
||||||
.frontmatter
|
.frontmatter
|
||||||
.get(&Value::String("is_root_note".to_string()))
|
.get(&Value::String("is_root_note".into()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if is_root_note != &Value::Bool(true) {
|
if is_root_note != &Value::Bool(true) {
|
||||||
// NOTE: Test failure may not give output consistently because the test binary affects
|
// 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| {
|
exporter.add_embed_postprocessor(&|ctx, _mdevents| {
|
||||||
let is_root_note = ctx
|
let is_root_note = ctx
|
||||||
.frontmatter
|
.frontmatter
|
||||||
.get(&Value::String("is_root_note".to_string()))
|
.get(&Value::String("is_root_note".into()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if is_root_note == &Value::Bool(true) {
|
if is_root_note == &Value::Bool(true) {
|
||||||
// NOTE: Test failure may not give output consistently because the test binary affects
|
// 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(),
|
tmp_dir.path().to_path_buf(),
|
||||||
);
|
);
|
||||||
let filter_by_tags = filter_by_tags(
|
let filter_by_tags = filter_by_tags(
|
||||||
vec!["private".to_string(), "no-export".to_string()],
|
vec!["private".into(), "no-export".into()],
|
||||||
vec!["export".to_string()],
|
vec!["export".into()],
|
||||||
);
|
);
|
||||||
exporter.add_postprocessor(&filter_by_tags);
|
exporter.add_postprocessor(&filter_by_tags);
|
||||||
exporter.run().unwrap();
|
exporter.run().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user