diff options
| author | Shulhan <ms@kilabit.info> | 2026-01-15 20:10:24 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-01-15 20:10:24 +0700 |
| commit | 32e4ea9ddf0c2d37f00fa81a4fb1dfe67420b8fe (patch) | |
| tree | dfd48a62d0fbd6ad8701cb86f487324d034a4ae7 | |
| parent | 735a82afd34af67cc3aa7e3ea84b766e25d6df84 (diff) | |
| download | spdxconv-32e4ea9ddf0c2d37f00fa81a4fb1dfe67420b8fe.tar.xz | |
all: add test for Scan on new file without git history
New file without git history should use the year from configuration.
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | spdxconv_test.go | 61 | ||||
| -rw-r--r-- | testdata/Scan_test.txt | 29 |
3 files changed, 34 insertions, 58 deletions
@@ -5,4 +5,6 @@ _doc/index.html cover.html cover.out cover.txt +testdata/scan/new_file.adoc testdata/scan/spdxconv.report +testdata/scan_no_scm/spdxconv.report diff --git a/spdxconv_test.go b/spdxconv_test.go index fe8ad1c..1496e14 100644 --- a/spdxconv_test.go +++ b/spdxconv_test.go @@ -140,6 +140,9 @@ func TestScan(t *testing.T) { dir: `testdata/scan/`, expReport: string(testData.Output[`scan/spdxconv.report`]), }, { + dir: `testdata/scan_no_scm/`, + expReport: string(testData.Output[`scan_no_scm/spdxconv.report`]), + }, { dir: `testdata/Scan_noConfigAndReport/`, expReport: string(testData.Output[`Scan_noConfigAndReport/spdxconv.report`]), }} @@ -334,61 +337,3 @@ func TestSPDXConv_scanFile(t *testing.T) { test.Assert(t, tc.dir+"/"+tc.name, tc.exp, got) } } - -func TestSPDXConv_scanDir(t *testing.T) { - type testCase struct { - dir string - exp []string - } - var listCase = []testCase{{ - dir: `testdata/scan/`, - exp: []string{ - `.gitignore`, - `Makefile`, - `a/b/.gitignore`, - `go.mod`, - `go.sum`, - `no_copyright_year.md`, - `po/included.go`, - `po/test.po`, - `po/test.pot`, - `test.go`, - `test.html`, - `test.json`, - `test.sh`, - `test.sql`, - `with_spdx.go`, - }, - }, { - dir: `testdata/scan_no_scm/`, - exp: []string{ - `test.go`, - `test.html`, - `test.sh`, - }, - }} - var tc testCase - var conv *SPDXConv - var err error - var got []string - for _, tc = range listCase { - t.Run(tc.dir, func(tt *testing.T) { - tt.Chdir(tc.dir) - - conv, err = New(`.`) - if err != nil { - tt.Fatal(err) - } - err = conv.prepareScan() - if err != nil { - t.Fatal(err) - } - - got, err = conv.scanDir([]string{`.`}) - if err != nil { - tt.Fatal(err) - } - test.Assert(tt, tc.dir, tc.exp, got) - }) - } -} diff --git a/testdata/Scan_test.txt b/testdata/Scan_test.txt index dca80da..7d09da5 100644 --- a/testdata/Scan_test.txt +++ b/testdata/Scan_test.txt @@ -3,6 +3,9 @@ Test spdxconv.Scan function. +>>> scan/new_file.adoc +New file without git history should use the year from configuration. + >>> scan/spdxconv.report // Reset the report. @@ -17,6 +20,7 @@ Test spdxconv.Scan function. // Makefile,default,0,2026,default,0,#, go.mod,default,0,2026,default,0,//, +new_file.adoc,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,//, @@ -40,6 +44,31 @@ po/test.po,,0,,,0,, po/test.pot,,0,,,0,, with_spdx.go,exist,0,,exist,1,//, +>>> scan_no_scm/spdxconv.report +// Reset the report. + +<<< scan_no_scm/spdxconv.report +// SPDX-License-Identifier: CC0-1.0 +// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> + +//spdxconv:version:v1 +//spdxconv:header:path,license_id,idx_license_id,year,copyright_id,idx_copyright_id +// +//spdxconv:regular +// +// +//spdxconv:binary +// +// +//spdxconv:unknown +// +test.go,,0,,,0,, +test.html,,0,,,0,, +test.sh,,0,,,0,, +// +//spdxconv:done +// + >>> Scan_noConfigAndReport/spdxconv.report // Reset the report. |
