-
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 2 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 ", | ||
"MIT+", | ||
} | ||
} | ||
|
||
#[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", | ||
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. 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 commentThe 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. |
||
"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", | ||
"MIT +", | ||
} | ||
} |
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.
While this is technically legal with the SPDX license expression syntax, I'd like to have future SPDX versions be able to error when
+
is applied to a license for which it makes no sense. I don't think the SPDX License List has any non-deprecated identifiers where+
makes sense, andGPL-3.0+
and similar are deprecated short identifiers even without a+
operator. So for testing+
, I'd prefer usingAGPL-1.0+
(andAGPL-1.0 +
where you haveMIT +
below). TheAGPL-1.0
identifier is deprecated in 3.1, but it exercises the+
operator in a way that makes legal sense.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.
I'm going to have to read a bit more around this, and see what other libraries are doing. I agree that
MIT+
doesn't make sense, but as you say it's technically legal.I'm thinking about how to add warnings to the API as well, for things like deprecated identifiers, so adding a
+
onto a license where it doesn't make sense could be a warning until the spec explicitly denies it.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.
That would be great (links to similar comments from here).
On the
MIT+
vs.AGPL-1.0+
front, have you settled on a preference? I preferAGPL-1.0+
because I weight "makes legal sense" more than "based on a non-deprecated identifier". But I don't feel stronlgy enough about it to hold up this PR, which looks good to me otherwise.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.
Changed the tests to use
AGPL-1.0+