aboutsummaryrefslogtreecommitdiff
path: root/testdata
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-12 20:22:20 +0700
committerShulhan <ms@kilabit.info>2026-01-12 21:22:24 +0700
commit1d6f8cfc60be1ada414ac1a9ce8eb6f61a527a0f (patch)
treeef0e990b8cd554e7ff6e9068339a1ce0485687fb /testdata
parent2a8ab762eabbe53f358eecd337872957d1afa01c (diff)
downloadspdxconv-1d6f8cfc60be1ada414ac1a9ce8eb6f61a527a0f.tar.xz
all: implement match-file-comment for seting comment based on file name
The first thing that the program do is to detect which comment string to be used when inserting SPDX identifiers in the file. For each pattern in the "match-file-comment" section, the program will match it with file name to get the comment prefix and suffix to be used later. User can add their own "match-file-comment" section as they like or modify the existing one. The "match-file-comment" can have empty prefix and suffix. That means, if the file name match, it will create new file with ".license" suffix that contains SPDX identifiers only, instead of inserting to the file.
Diffstat (limited to 'testdata')
-rw-r--r--testdata/Apply_test.txt68
-rw-r--r--testdata/Init/.gitignore5
-rw-r--r--testdata/scan/spdxconv.cfg35
3 files changed, 93 insertions, 15 deletions
diff --git a/testdata/Apply_test.txt b/testdata/Apply_test.txt
index 712c2bc..43360b4 100644
--- a/testdata/Apply_test.txt
+++ b/testdata/Apply_test.txt
@@ -4,13 +4,48 @@
// REUSE-IgnoreStart
>>> spdxconv.cfg
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
[default]
license_identifier = GPL-3.0-only
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 = "^.*\\.(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
@@ -19,23 +54,26 @@ delete_line_pattern = "^(//+|#+)\\s+license that(.*)$"
[match-copyright]
pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<contact>.*)>.*$"
->>> without_spdx_license_id.txt
+>>> without_spdx_license_id.go
1
2
3
-<<< without_spdx_license_id.txt
+<<< without_spdx_license_id.go
+// SPDX-License-Identifier: GPL-3.0-only
+// SPDX-FileCopyrightText: M. Shulhan <ms@kilabit.info>
+
1
2
3
->>> with_spdx_at_bottom.txt
+>>> with_spdx_at_bottom.go
1
2
3
// SPDX-License-Identifier: GPL-3.0-only
-<<< with_spdx_at_bottom.txt
+<<< with_spdx_at_bottom.go
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: M. Shulhan <ms@kilabit.info>
@@ -43,13 +81,13 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
->>> with_spdx_license_id_only.txt
+>>> with_spdx_license_id_only.go
// SPDX-License-Identifier: GPL-3.0-only
1
2
3
-<<< with_spdx_license_id_only.txt
+<<< with_spdx_license_id_only.go
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: M. Shulhan <ms@kilabit.info>
@@ -57,7 +95,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
->>> with_spdx.txt
+>>> with_spdx.go
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2018 Shulhan <ms@kilabit.info>
@@ -65,7 +103,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
-<<< with_spdx.txt
+<<< with_spdx.go
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2018 Shulhan <ms@kilabit.info>
@@ -73,7 +111,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
->>> with_spdx_no_order.txt
+>>> with_spdx_no_order.go
// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: BSD-3-Clause
@@ -81,7 +119,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
-<<< with_spdx_no_order.txt
+<<< with_spdx_no_order.go
// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: BSD-3-Clause
@@ -89,7 +127,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
->>> with_match_license.txt
+>>> with_match_license.go
// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -98,7 +136,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
-<<< with_match_license.txt
+<<< with_match_license.go
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2018 Shulhan <ms@kilabit.info>
@@ -106,7 +144,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
->>> with_match_license_bottom.txt
+>>> with_match_license_bottom.go
1
2
3
@@ -115,7 +153,7 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-<<< with_match_license_bottom.txt
+<<< with_match_license_bottom.go
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2018 Shulhan <ms@kilabit.info>
diff --git a/testdata/Init/.gitignore b/testdata/Init/.gitignore
new file mode 100644
index 0000000..234c892
--- /dev/null
+++ b/testdata/Init/.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/scan/spdxconv.cfg b/testdata/scan/spdxconv.cfg
index ec401a3..d317d64 100644
--- a/testdata/scan/spdxconv.cfg
+++ b/testdata/scan/spdxconv.cfg
@@ -6,6 +6,41 @@ license_identifier = GPL-3.0-only
file_copyright_text = Author <contact@email.local>
max_line_match = 10
+[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