mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-19 01:57:49 -04:00
Verify that SPDX-License-Identifier headers at the top of source files are parsed correctly. Assisted-by: Cursor:claude-sonnet-4-5 Assisted-by: OpenCode:GLM-4-7 Co-developed-by: Maximilian Huber <maximilian.huber@tngtech.com> Signed-off-by: Maximilian Huber <maximilian.huber@tngtech.com> Signed-off-by: Luis Augenstein <luis.augenstein@tngtech.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
# SPDX-License-Identifier: GPL-2.0-only OR MIT
|
|
# Copyright (C) 2025 TNG Technology Consulting GmbH
|
|
|
|
import unittest
|
|
from pathlib import Path
|
|
import tempfile
|
|
from sbom.spdx_graph.kernel_file import _parse_spdx_license_identifier # type: ignore
|
|
|
|
|
|
class TestKernelFile(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmpdir = tempfile.TemporaryDirectory()
|
|
self.src_tree = Path(self.tmpdir.name)
|
|
|
|
def tearDown(self):
|
|
self.tmpdir.cleanup()
|
|
|
|
def test_parse_spdx_license_identifier(self):
|
|
# REUSE-IgnoreStart
|
|
test_cases: list[tuple[str, str | None]] = [
|
|
("/* SPDX-License-Identifier: MIT*/", "MIT"),
|
|
("// SPDX-License-Identifier: GPL-2.0-only", "GPL-2.0-only"),
|
|
("# SPDX-License-Identifier: GPL-2.0-only", "GPL-2.0-only"),
|
|
("#!/bin/bash\n# SPDX-License-Identifier: GPL-2.0-only", "GPL-2.0-only"),
|
|
("/* SPDX-License-Identifier: GPL-2.0-or-later OR MIT */", "GPL-2.0-or-later OR MIT"),
|
|
("/* SPDX-License-Identifier: Apache-2.0 */\n extra text", "Apache-2.0"),
|
|
("<!-- SPDX-License-Identifier: GPL-2.0 -->", "GPL-2.0"),
|
|
("int main() { return 0; }", None),
|
|
]
|
|
# REUSE-IgnoreEnd
|
|
|
|
for i, (file_content, expected_identifier) in enumerate(test_cases):
|
|
file_path = self.src_tree / f"file_{i}.c"
|
|
file_path.write_text(file_content)
|
|
self.assertEqual(_parse_spdx_license_identifier(str(file_path)), expected_identifier)
|