Skip to content

Commit

Permalink
Fix issue with bans codes as args (#615)
Browse files Browse the repository at this point in the history
An issue was introduced in [#605
](#605 (comment))
as I had commented out code while iterating on changes and forgot to add
back this case because it wasn't covered by any tests. I've added a
snapshot test to catch it in the future, as well as added the
`deprecated` code to the list of options.
  • Loading branch information
Jake-Shadle committed Feb 24, 2024
1 parent d51e114 commit ea36bf2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,31 @@ struct NodePrint {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DiagnosticCode {
Advisory(crate::advisories::Code),
//Bans(crate::bans::Code),
Bans(crate::bans::Code),
License(crate::licenses::Code),
Source(crate::sources::Code),
General(general::Code),
}

impl DiagnosticCode {
pub fn iter() -> impl Iterator<Item = Self> {
use strum::IntoEnumIterator;
crate::advisories::Code::iter()
.map(Self::Advisory)
//.chain(crate::bans::Code::iter().map(Self::Bans))
.chain(crate::bans::Code::iter().map(Self::Bans))
.chain(crate::licenses::Code::iter().map(Self::License))
.chain(crate::sources::Code::iter().map(Self::Source))
.chain(general::Code::iter().map(Self::General))
}

#[inline]
pub fn as_str(self) -> &'static str {
match self {
Self::Advisory(code) => code.into(),
//Self::Bans(code) => code.into(),
Self::Bans(code) => code.into(),
Self::License(code) => code.into(),
Self::Source(code) => code.into(),
Self::General(code) => code.into(),
}
}
}
Expand All @@ -301,9 +304,10 @@ impl std::str::FromStr for DiagnosticCode {
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse::<crate::advisories::Code>()
.map(Self::Advisory)
//.or_else(|_err| s.parse::<crate::bans::Code>().map(Self::Bans))
.or_else(|_err| s.parse::<crate::bans::Code>().map(Self::Bans))
.or_else(|_err| s.parse::<crate::licenses::Code>().map(Self::License))
.or_else(|_err| s.parse::<crate::sources::Code>().map(Self::Source))
.or_else(|_err| s.parse::<general::Code>().map(Self::General))
}
}

Expand All @@ -319,5 +323,7 @@ mod test {
panic!("existing code '{code}'");
}
}

insta::assert_debug_snapshot!(unique);
}
}
62 changes: 62 additions & 0 deletions src/snapshots/cargo_deny__diag__test__codes_unique.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
source: src/diag.rs
expression: unique
---
{
"accepted",
"advisory-ignored",
"advisory-not-detected",
"allowed",
"allowed-by-organization",
"allowed-by-wrapper",
"allowed-source",
"banned",
"build-script-not-allowed",
"checksum-match",
"checksum-mismatch",
"default-feature-enabled",
"denied-by-extension",
"deprecated",
"detected-executable",
"detected-executable-script",
"duplicate",
"exact-features-mismatch",
"feature-banned",
"feature-not-explicitly-allowed",
"features-enabled",
"git-source-underspecified",
"index-cache-load-failure",
"index-failure",
"license-exception-not-encountered",
"license-not-encountered",
"missing-clarification-file",
"not-allowed",
"notice",
"path-bypassed",
"path-bypassed-by-glob",
"rejected",
"skipped",
"skipped-by-root",
"skipped-private-workspace-crate",
"source-not-allowed",
"unable-to-check-path",
"unknown-advisory",
"unknown-feature",
"unlicensed",
"unmaintained",
"unmatched-bypass",
"unmatched-glob",
"unmatched-organization",
"unmatched-path-bypass",
"unmatched-skip",
"unmatched-skip-root",
"unmatched-source",
"unmatched-wrapper",
"unsound",
"unused-wrapper",
"vulnerability",
"wildcard",
"yanked",
"yanked-ignored",
"yanked-not-detected",
}

0 comments on commit ea36bf2

Please sign in to comment.