Skip to content

Commit 71128eb

Browse files
committed
Merge branch 'ThorstenHarter-develop' into develop
2 parents 7101e3d + 4b40f39 commit 71128eb

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

src/formattedcode/output_spdx.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,11 @@ def write_spdx(output_file, results, scancode_version, scancode_notice,
292292
# Therefore in one case we do nothing (rdf) and in the other case we
293293
# encode to UTF8 bytes.
294294

295-
from StringIO import StringIO
296-
spdx_output = StringIO()
297-
write_document(doc, spdx_output, validate=True)
298-
result = spdx_output.getvalue()
299-
if as_tagvalue:
300-
result = result.encode('utf-8')
301-
output_file.write(result)
295+
if package.files:
296+
from StringIO import StringIO
297+
spdx_output = StringIO()
298+
write_document(doc, spdx_output, validate=True)
299+
result = spdx_output.getvalue()
300+
if as_tagvalue:
301+
result = result.encode('utf-8')
302+
output_file.write(result)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No results for package 'scan'.

tests/formattedcode/data/spdx/empty/scan/somefile

Whitespace-only changes.

tests/formattedcode/test_output_spdx.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,22 @@ def test_spdx_rdf_with_or_later_license_does_not_fail():
269269
'--license-diag', test_file, '--output-spdx-rdf', result_file]
270270
run_scan_plain(args)
271271
check_rdf_scan(expected_file, result_file)
272+
273+
274+
def test_spdx_tv_with_empty_scan():
275+
test_file = test_env.get_test_loc('spdx/empty/scan')
276+
result_file = test_env.get_temp_file('spdx.tv')
277+
expected_file = test_env.get_test_loc('spdx/empty/expected.tv')
278+
args = ['--license', '--strip-root', '--info', '--only-findings', test_file, '--output-spdx-tv', result_file]
279+
run_scan_plain(args)
280+
check_tv_scan(expected_file, result_file, regen=True)
281+
282+
283+
def test_spdx_rdf_with_empty_scan():
284+
test_file = test_env.get_test_loc('spdx/empty/scan')
285+
result_file = test_env.get_temp_file('spdx.rdf')
286+
args = ['--license', '--strip-root', '--info', '--only-findings', test_file, '--output-spdx-rdf', result_file]
287+
run_scan_plain(args)
288+
expected = "<!-- No results for package 'scan'. -->\n"
289+
results = open(result_file).read()
290+
assert expected == results

0 commit comments

Comments
 (0)