aboutsummaryrefslogtreecommitdiff
path: root/spdxconv_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'spdxconv_test.go')
-rw-r--r--spdxconv_test.go82
1 files changed, 33 insertions, 49 deletions
diff --git a/spdxconv_test.go b/spdxconv_test.go
index 84b3718..d2389e4 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -8,7 +8,6 @@ import (
"regexp"
"testing"
- "git.sr.ht/~shulhan/pakakeh.go/lib/git"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
@@ -121,54 +120,46 @@ func TestInit(t *testing.T) {
}
func TestScan(t *testing.T) {
- const scanDir = `testdata/scan/`
- t.Chdir(scanDir)
+ // Populate the test files into `testdata/`.
- err := Scan(`.`)
+ var testData *test.Data
+ var err error
+ testData, err = test.LoadData(`testdata/Scan_test.txt`)
if err != nil {
t.Fatal(err)
}
+ var tempDir = `testdata/`
+ testData.ExtractInput(tempDir)
- got, err := os.ReadFile(ReportFile)
- if err != nil {
- t.Fatal(err)
- }
+ // Run the test ...
- exp := `// SPDX-License-Identifier: CC0-1.0
-// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
+ listCase := []struct {
+ dir string
+ expReport string
+ }{{
+ dir: `testdata/scan/`,
+ expReport: string(testData.Output[`scan/spdxconv.report`]),
+ }, {
+ dir: `testdata/Scan_noConfigAndReport/`,
+ expReport: string(testData.Output[`Scan_noConfigAndReport/spdxconv.report`]),
+ }}
+ for _, tc := range listCase {
+ t.Run(tc.dir, func(tt *testing.T) {
+ tt.Chdir(tc.dir)
-//spdxconv:version:v1
-//spdxconv:header:path,license_id,idx_license_id,year,copyright_id,idx_copyright_id
-//
-//spdxconv:regular
-//
-Makefile,default,0,2025,default,0,#,
-go.mod,default,0,2025,default,0,//,
-no_copyright_year.md,match,2,2026,default,0,<!--,-->
-po/included.go,match,1,2026,match,0,//,
-test.go,match,1,2022,match,0,//,
-test.html,match,4,2022,match,1,<!--,-->
-test.sh,default,0,2026,default,0,#,
-test.sql,match,1,2022,match,0,--,
-//
-//spdxconv:binary
-//
-go.sum,default,0,2025,default,0,,
-test.json,default,0,2026,default,0,,
-//
-//spdxconv:unknown
-//
-//
-//spdxconv:done
-//
-.gitignore,exist,0,,exist,1,#,
-a/b/.gitignore,exist,0,,exist,1,#,
-po/test.po,,0,,,0,,
-po/test.pot,,0,,,0,,
-with_spdx.go,exist,0,,exist,1,//,
-`
+ err := Scan(`.`)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ got, err := os.ReadFile(ReportFile)
+ if err != nil {
+ t.Fatal(err)
+ }
- test.Assert(t, `Scan: `+scanDir, exp, string(got))
+ test.Assert(t, `Scan: `+tc.dir, tc.expReport, string(got))
+ })
+ }
}
func TestApply(t *testing.T) {
@@ -259,19 +250,12 @@ func TestNew(t *testing.T) {
testData.ExtractInput(tempDir)
t.Chdir(tempDir)
- var gitRoot *git.Git
- gitRoot, err = git.New(`.`)
- if err != nil {
- t.Fatal(err)
- }
-
var listCase = []testCase{{
dir: `.`,
exp: &SPDXConv{
curDir: tempDir,
dir: tempDir,
- scmDir: tempDir,
- scm: gitRoot,
+ scm: defaultNoSCM,
},
}, {
dir: `/tmp`,