diff options
| -rw-r--r-- | file.go | 3 | ||||
| -rw-r--r-- | spdxconv_test.go | 32 | ||||
| -rw-r--r-- | testdata/Apply_fromReport/.gitignore | 5 | ||||
| -rw-r--r-- | testdata/Apply_fromReport_test.txt | 76 | ||||
| -rw-r--r-- | testdata/Apply_test.txt | 6 |
5 files changed, 122 insertions, 0 deletions
@@ -95,6 +95,9 @@ func (f *file) initLines(content []byte, maxLine int) (err error) { if err != nil { return err } + if len(content) == 0 { + return nil + } } f.lines = bytes.Split(content, []byte{'\n'}) diff --git a/spdxconv_test.go b/spdxconv_test.go index aa37cba..f473a2e 100644 --- a/spdxconv_test.go +++ b/spdxconv_test.go @@ -189,6 +189,38 @@ func TestApply(t *testing.T) { } } +func TestApply_fromReport(t *testing.T) { + // Populate the test files. + + var testData *test.Data + var err error + testData, err = test.LoadData(`testdata/Apply_fromReport_test.txt`) + if err != nil { + t.Fatal(err) + } + var tempDir = `testdata/Apply_fromReport/` + testData.ExtractInput(tempDir) + t.Chdir(tempDir) + + err = Apply() + if err != nil { + t.Fatal(err) + } + + for input, _ := range testData.Input { + if input == ConfigFile || input == ReportFile { + continue + } + + got, err := os.ReadFile(input) + if err != nil { + t.Fatal(err) + } + test.Assert(t, input+`: after`, + string(testData.Output[input]), string(got)) + } +} + func TestNew(t *testing.T) { type testCase struct { exp *SPDXConv diff --git a/testdata/Apply_fromReport/.gitignore b/testdata/Apply_fromReport/.gitignore new file mode 100644 index 0000000..234c892 --- /dev/null +++ b/testdata/Apply_fromReport/.gitignore @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> + +/* +!/.gitignore diff --git a/testdata/Apply_fromReport_test.txt b/testdata/Apply_fromReport_test.txt new file mode 100644 index 0000000..33d4e85 --- /dev/null +++ b/testdata/Apply_fromReport_test.txt @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> + +// REUSE-IgnoreStart + +>>> spdxconv.cfg +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> + +[default] +license_identifier = GPL-3.0-only +copyright_year = 2026 +file_copyright_text = M. Shulhan <ms@kilabit.info> + +[match-file-comment] +pattern = "^.*\\.(adoc|asciidoc|c|cc|cpp|cs|dart|go|h|hh|hpp|java|js|jsx|jsonc|kt|kts|php|rs|sass|scss|swift|ts|tsx)$" +prefix = "//" + +[match-file-comment] +pattern = "^.*\\.(aff|bash|csh|dockerfile|env|gitignore|hcl|ipynb|make|pl|pm|py|ps1|rb|sh|tf|yaml|yml|zsh)$" +prefix = "#" + +[match-file-comment] +pattern = "^.*\\.(css)$" +prefix = "/*" +suffix = "*/" + +[match-file-comment] +pattern = "^.*\\.(fxml|htm|html|html5|kml|markdown|md|xml)$" +prefix = "<!--" +suffix = "-->" + +[match-file-comment] +pattern = "^.*\\.(lua|sql)$" +prefix = "--" + +[match-file-comment] +pattern = "^.*\\.(rst)$" +prefix = ".." + +[match-file-comment] +pattern = "^.*\\.(tex)$" +prefix = "%" + +# File name that match with this pattern will have the ".license" file +# created. +[match-file-comment] +pattern = "^.*\\.(apk|app|bz2|csv|doc|docx|exe|gif|gz|jpeg|jpg|json|pdf|png|ppt|pptx|svg|svgz|tar|tgz|xls|xlsx|zip)$" + +[match-license] +pattern = "^(//+|#+|/\\*+|<!--+|--+)?\\s*(.*)governed by a BSD-style(.*)$" +license_identifier = BSD-3-Clause +delete_line_before = "^(//+|#+|/\\*+|<!--+|--+)$" +delete_line_after = "^(//+|#+|/\\*+|<!--+|--+)?\\s*license that can(.*)$" +delete_line_after = "^(//+|#+|\\*+/|--+>|--+)$" + +[match-copyright] +pattern = "^(//+|#+|/\\*+|<!--+|--+)?\\s*Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<(?<contact>.*)>.*$" +delete_line_before = "^(//+|#+|/\\*+|<!--+|--+)$" +delete_line_after = "^(//+|#+|\\*+/|--+>|--+)$" + +>>> spdxconv.report + +//spdxconv:regular +empty.html,default,0,2026,default,0,<!-- ," -->" +//spdxconv:binary +//spdxconv:unknown + +>>> empty.html + +<<< empty.html +<!-- SPDX-License-Identifier: GPL-3.0-only --> +<!-- SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> --> + +<<< END +// REUSE-IgnoreEnd diff --git a/testdata/Apply_test.txt b/testdata/Apply_test.txt index a8c3e6d..13ee6be 100644 --- a/testdata/Apply_test.txt +++ b/testdata/Apply_test.txt @@ -59,6 +59,12 @@ pattern = "^(//+|#+|/\\*+|<!--+|--+)?\\s*Copyright\\s+(?<year>\\d{4}),?\\s+(?<au delete_line_before = "^(//+|#+|/\\*+|<!--+|--+)$" delete_line_after = "^(//+|#+|\\*+/|--+>|--+)$" +>>> empty.html + +<<< empty.html +<!-- SPDX-License-Identifier: GPL-3.0-only --> +<!-- SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> --> + >>> without_spdx_license_id.go 1 2 |
