Debian Codegraph @

spdxexp/extracts_test.go

raw symbols SCIP
1 package spdxexpscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/
2
3 import (
4 "contextscip-go gomod github.com/golang/go/src go1.24 context/"
5 "osscip-go gomod github.com/golang/go/src go1.24 os/"
6 "os/execscip-go gomod github.com/golang/go/src go1.24 `os/exec`/"
7 "testingscip-go gomod github.com/golang/go/src go1.24 testing/"
8 "timescip-go gomod github.com/golang/go/src go1.24 time/"
9
10 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/"
11 )
12
13 const kernelHeadersLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/kernelHeadersLicense. = `(GPL-2.0-only WITH Linux-syscall-note OR BSD-2-Clause) AND (GPL-2.0-only WITH Linux-syscall-note OR BSD-3-Clause) AND (GPL-2.0-only WITH Linux-syscall-note OR CDDL-1.0) AND (GPL-2.0-only WITH Linux-syscall-note OR Linux-OpenIB) AND (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (GPL-2.0-or-later WITH Linux-syscall-note OR BSD-3-Clause) AND (GPL-2.0-or-later WITH Linux-syscall-note OR MIT) AND Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-3-Clause-Clear AND GFDL-1.1-no-invariants-or-later AND GPL-1.0-or-later AND (GPL-1.0-or-later OR BSD-3-Clause) AND GPL-1.0-or-later WITH Linux-syscall-note AND GPL-2.0-only AND (GPL-2.0-only OR Apache-2.0) AND (GPL-2.0-only OR BSD-2-Clause) AND (GPL-2.0-only OR BSD-3-Clause) AND (GPL-2.0-only OR CDDL-1.0) AND (GPL-2.0-only OR GFDL-1.1-no-invariants-or-later) AND (GPL-2.0-only OR GFDL-1.2-no-invariants-only) AND GPL-2.0-only WITH Linux-syscall-note AND GPL-2.0-or-later AND (GPL-2.0-or-later OR BSD-2-Clause) AND (GPL-2.0-or-later OR BSD-3-Clause) AND (GPL-2.0-or-later OR CC-BY-4.0) AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GPL-2.0-or-later WITH Linux-syscall-note AND ISC AND LGPL-2.0-or-later AND (LGPL-2.0-or-later OR BSD-2-Clause) AND LGPL-2.0-or-later WITH Linux-syscall-note AND LGPL-2.1-only AND (LGPL-2.1-only OR BSD-2-Clause) AND LGPL-2.1-only WITH Linux-syscall-note AND LGPL-2.1-or-later AND LGPL-2.1-or-later WITH Linux-syscall-note AND (Linux-OpenIB OR GPL-2.0-only) AND (Linux-OpenIB OR GPL-2.0-only OR BSD-2-Clause) AND Linux-man-pages-copyleft AND MIT AND (MIT OR GPL-2.0-only) AND (MIT OR GPL-2.0-or-later) AND (MIT OR LGPL-2.1-only) AND (MPL-1.1 OR GPL-2.0-only) AND (X11 OR GPL-2.0-only) AND (X11 OR GPL-2.0-or-later) AND Zlib AND (copyleft-next-0.3.1 OR GPL-2.0-or-later)`
14
15 var expectedKernelHeadersLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expectedKernelHeadersLicenses. = []string{
16 "GPL-2.0-only WITH Linux-syscall-note",
17 "BSD-2-Clause",
18 "BSD-3-Clause",
19 "CDDL-1.0",
20 "Linux-OpenIB",
21 "MIT",
22 "GPL-2.0-or-later WITH Linux-syscall-note",
23 "Apache-2.0",
24 "BSD-3-Clause-Clear",
25 "GFDL-1.1-no-invariants-or-later",
26 "GPL-1.0-or-later",
27 "GPL-1.0-or-later WITH Linux-syscall-note",
28 "GPL-2.0-only",
29 "GFDL-1.2-no-invariants-only",
30 "GPL-2.0-or-later",
31 "CC-BY-4.0",
32 "GPL-2.0-or-later WITH GCC-exception-2.0",
33 "ISC",
34 "LGPL-2.0-or-later",
35 "LGPL-2.0-or-later WITH Linux-syscall-note",
36 "LGPL-2.1-only",
37 "LGPL-2.1-only WITH Linux-syscall-note",
38 "LGPL-2.1-or-later",
39 "LGPL-2.1-or-later WITH Linux-syscall-note",
40 "Linux-man-pages-copyleft",
41 "MPL-1.1",
42 "X11",
43 "Zlib",
44 "copyleft-next-0.3.1",
45 }
46
47 func TestExtractLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestExtractLicenses().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) {
48 tests := []struct {
49 name string
50 inputExpression string
51 extractedLicenses []string
52 }{
53 {"Single license", "MIT", []string{"MIT"}},
54 {"AND'ed licenses", "MIT AND Apache-2.0", []string{"MIT", "Apache-2.0"}},
55 {"AND'ed & OR'ed licenses", "(MIT AND Apache-2.0) OR GPL-3.0", []string{"GPL-3.0", "MIT", "Apache-2.0"}},
56 {"ONLY modifiers", "LGPL-2.1-only OR MIT OR BSD-3-Clause", []string{"MIT", "BSD-3-Clause", "LGPL-2.1-only"}},
57 {"WITH modifiers", "GPL-2.0-or-later WITH Bison-exception-2.2", []string{"GPL-2.0-or-later WITH Bison-exception-2.2"}},
58 {"Invalid SPDX expression", "MIT OR INVALID", nil},
59 {"-or-later suffix with mixed case", "GPL-2.0-Or-later", []string{"GPL-2.0-or-later"}},
60 {"+ operator in Apache", "APACHE-2.0+", []string{"Apache-2.0+"}},
61 {"+ operator in GPL", "GPL-2.0+", []string{"GPL-2.0-or-later"}},
62 }
63
64 for _, test := range tests {
65 t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) {
66 licenses, err := ExtractLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ExtractLicenses().(test.inputExpression)
67 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.ElementsMatchscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/ElementsMatch().(t, test.extractedLicenses, licenses)
68 if test.extractedLicenses == nil {
69 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Error().(t, err)
70 } else {
71 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
72 }
73 })
74 }
75 }
76
77 func TestExtractLicensesLicenseRefAndDedupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestExtractLicensesLicenseRefAndDedup().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) {
78 licenses, err := ExtractLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ExtractLicenses().("(LicenseRef-custom OR LicenseRef-custom) AND (DocumentRef-spdx-tool-1.2:LicenseRef-custom OR MIT)")
79 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
80 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.ElementsMatchscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/ElementsMatch().(t, []string{"LicenseRef-custom", "DocumentRef-spdx-tool-1.2:LicenseRef-custom", "MIT"}, licenses)
81 }
82
83 func TestExtractLicensesLongExpressionDoesNotHangscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestExtractLicensesLongExpressionDoesNotHang().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) {
84 if osscip-go gomod github.com/golang/go/src go1.24 os/.Getenvscip-go gomod github.com/golang/go/src go1.24 os/Getenv().("GO_SPDX_EXTRACT_LICENSES_LONG_CHILD") == "1" {
85 licenses, err := ExtractLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ExtractLicenses().(kernelHeadersLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/kernelHeadersLicense.)
86 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
87 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.ElementsMatchscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/ElementsMatch().(t, expectedKernelHeadersLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expectedKernelHeadersLicenses., licenses)
88 return
89 }
90
91 ctx, cancel := contextscip-go gomod github.com/golang/go/src go1.24 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.24 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.24 context/.Backgroundscip-go gomod github.com/golang/go/src go1.24 context/Background().(), 5*timescip-go gomod github.com/golang/go/src go1.24 time/.Secondscip-go gomod github.com/golang/go/src go1.24 time/Second.)
92 defer cancel()
93
94 // #nosec G204 G702 -- safe in tests: re-executes current test binary with fixed arg
95 cmd := execscip-go gomod github.com/golang/go/src go1.24 `os/exec`/.CommandContextscip-go gomod github.com/golang/go/src go1.24 `os/exec`/CommandContext().(ctx, osscip-go gomod github.com/golang/go/src go1.24 os/.Argsscip-go gomod github.com/golang/go/src go1.24 os/Args.[0], "-test.run", "^TestExtractLicensesLongExpressionDoesNotHang$")
96 cmd.Envscip-go gomod github.com/golang/go/src go1.24 `os/exec`/Cmd#Env. = append(osscip-go gomod github.com/golang/go/src go1.24 os/.Environscip-go gomod github.com/golang/go/src go1.24 os/Environ().(), "GO_SPDX_EXTRACT_LICENSES_LONG_CHILD=1")
97 output, err := cmd.CombinedOutputscip-go gomod github.com/golang/go/src go1.24 `os/exec`/Cmd#CombinedOutput().()
98 if ctx.Errscip-go gomod github.com/golang/go/src go1.24 context/Context#Err().() == contextscip-go gomod github.com/golang/go/src go1.24 context/.DeadlineExceededscip-go gomod github.com/golang/go/src go1.24 context/DeadlineExceeded. {
99 t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("ExtractLicenses timed out on long expression: %s", output)
100 }
101 if err != nil {
102 t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("child process failed: %v\n%s", err, output)
103 }
104 }