From a4f0527f38bc9afd5f6999f6b3ad043fcd053d18 Mon Sep 17 00:00:00 2001 From: Simon Ensslen Date: Tue, 30 Sep 2025 08:27:36 +0200 Subject: [PATCH 1/2] add testcase for real mit license that does not match --- .../LicenseMatcherTest.cs | 24 +++++++++++++++++++ .../MIT__fromOpensource.txt} | 2 +- .../SPDXLicenseMatcher.Test.csproj | 4 +--- 3 files changed, 26 insertions(+), 4 deletions(-) rename tests/SPDXLicenseMatcher.Test/{NonSpdxTestLicenses/AlmostMit.txt => RealLicenses/MIT__fromOpensource.txt} (98%) diff --git a/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs b/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs index c4627eb6..0430469a 100644 --- a/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs +++ b/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs @@ -51,6 +51,23 @@ public static IEnumerable> GetCases() } } + public static class RealWorldLicenses + { + private const string PREFIX = "SPDXLicenseMatcher.Test.RealLicenses."; + private static readonly int s_prefixLength = PREFIX.Length; + public static IEnumerable> GetCases() + { + var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + foreach (string name in executingAssembly.GetManifestResourceNames().Where(n => n.StartsWith(PREFIX)).Where(n => n.EndsWith("txt"))) + { + string fileName = name.Substring(s_prefixLength); + string expectedIdentifier = fileName.Split("__")[0]; + using var reader = new StreamReader(executingAssembly.GetManifestResourceStream(name)!); + yield return () => new Case(expectedIdentifier, reader.ReadToEnd()); + } + } + } + #pragma warning disable S125 // Sections of code should not be commented out /* [Test] @@ -78,5 +95,12 @@ public async Task Fast_License_Matcher_Should_Not_Pick_A_License(string licenseT { await Assert.That(FastlicenseMatcher.Match(licenseText)).IsEmpty(); } + + [Test] + [MethodDataSource(typeof(RealWorldLicenses), nameof(RealWorldLicenses.GetCases))] + public async Task Fast_License_Matcher_Should_Mattch_Real_World_Licenses(Case @case) + { + await Assert.That(FastlicenseMatcher.Match(@case.Content)).Contains(@case.Identifier); + } } } diff --git a/tests/SPDXLicenseMatcher.Test/NonSpdxTestLicenses/AlmostMit.txt b/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt similarity index 98% rename from tests/SPDXLicenseMatcher.Test/NonSpdxTestLicenses/AlmostMit.txt rename to tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt index bf9dace0..8cad1cac 100644 --- a/tests/SPDXLicenseMatcher.Test/NonSpdxTestLicenses/AlmostMit.txt +++ b/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt @@ -6,4 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj b/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj index 069920a2..a4243a29 100644 --- a/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj +++ b/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj @@ -29,9 +29,7 @@ - - - + From 908a1be7ebbfd6a72dac09ca8656bac15a4ee6b5 Mon Sep 17 00:00:00 2001 From: Simon Ensslen Date: Sun, 12 Oct 2025 21:07:30 +0200 Subject: [PATCH 2/2] it seems https://opensource.org/license/mit got corrected - there is still value in the new tests though - so update --- src/SPDXLicenseMatcher/FastLicenseMatcher.cs | 1 - .../RealLicenses/MIT__fromOpensource.txt | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SPDXLicenseMatcher/FastLicenseMatcher.cs b/src/SPDXLicenseMatcher/FastLicenseMatcher.cs index 1173f511..8b17f4eb 100644 --- a/src/SPDXLicenseMatcher/FastLicenseMatcher.cs +++ b/src/SPDXLicenseMatcher/FastLicenseMatcher.cs @@ -32,7 +32,6 @@ public class FastLicenseMatcher : ILicenseMatcher private static readonly Regex BEGIN_OPTIONAL_COMMENT_PATTERN = new Regex("^\\s*<>\\s*" + START_COMMENT_CHAR_PATTERN, RegexOptions.Compiled); #pragma warning restore IDE1006 - private readonly IImmutableDictionary _templateInstructions; public FastLicenseMatcher(IDictionary licenses) diff --git a/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt b/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt index 8cad1cac..5e9b8194 100644 --- a/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt +++ b/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt @@ -2,8 +2,8 @@ MIT License Copyright (c) 2025 John Doe -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.