-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend test cases #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
extern crate license_exprs; | ||
|
||
use license_exprs::validate_license_expr; | ||
|
||
macro_rules! assert_licenses_ok { | ||
($($license:expr),+ $(,)+) => {{ | ||
$(assert!(validate_license_expr($license).is_ok());)+ | ||
}} | ||
} | ||
|
||
macro_rules! assert_licenses_err { | ||
($($license:expr),+ $(,)+) => {{ | ||
$(assert!(validate_license_expr($license).is_err());)+ | ||
}} | ||
} | ||
|
||
#[test] | ||
fn single_license() { | ||
assert_licenses_ok! { | ||
"MIT", | ||
"MIT ", | ||
" MIT", | ||
" MIT ", | ||
" MIT ", | ||
"AGPL-1.0+", | ||
} | ||
} | ||
|
||
#[test] | ||
fn compound_license() { | ||
assert_licenses_ok! { | ||
"GPL-3.0+ WITH Classpath-exception-2.0 OR MIT AND AAL", | ||
"MIT AND Apache-2.0", | ||
"MIT OR Apache-2.0", | ||
"GPL-3.0+ WITH Classpath-exception-2.0", | ||
"MIT AND Apache-2.0", | ||
} | ||
} | ||
|
||
#[test] | ||
fn fails_invalid_license() { | ||
assert_licenses_err! { | ||
"asdfghjkl", | ||
"MIT AND qwerty", | ||
} | ||
} | ||
|
||
#[test] | ||
fn fails_incorrect_structure() { | ||
assert_licenses_err! { | ||
"()", | ||
"(MIT", | ||
"MIT)", | ||
"MIT Apache-2.0", | ||
"MIT and Apache-2.0", | ||
"MIT or Apache-2.0", | ||
"GPL-3.0+ with Classpath-exception-2.0", | ||
"MIT (MIT AND MIT)", | ||
"(MIT AND MIT) MIT", | ||
"and Apache-2.0", | ||
"(MIT and Apache-2.0 and )", | ||
"MIT xor Apache-2.0", | ||
"WITH", | ||
"MIT OR WITH", | ||
// "MIT WITH", // TODO: Incorrectly marked as valid | ||
// "MIT AND", // TODO: Incorrectly marked as valid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a Rust analog to TAP's TODO tests for marking expected test failures? It would be nice to report these known failures as non-fatal warnings in the test results and be prompted to remove the TODO once we fix the backing implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in the default test runner that I know of. I'm hopefully going to fix these errors soon when I work on parsing to an actual syntax tree, which will also involve adding a whole bunch more test cases, so I think keeping them as just comments for now should be ok. |
||
"MIT AND Classpath-exception-2.0", | ||
"Classpath-exception-2.0 WITH MIT", | ||
"Classpath-exception-2.0", | ||
"AGPL-1.0 +", | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some discussion about making operators case insensitive in spdx/spdx-spec#63, but the 2.1 ABNF requires uppercase operators. So I'm fine requiring failures here for now, but we may need to revisit these if the SPDX discussion results in them (or license expressions as a whole) becoming case insensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I presume that can be done as a non-breaking enhancement to the spec so the same can happen here.