Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spdx/parsers/tagvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def p_extr_lic_id_2(self, p):
self.logger.log(msg)

def p_uknown_tag(self, p):
"""unknown_tag : UNKNOWN_TAG"""
"""unknown_tag : UNKNOWN_TAG LINE"""
self.error = True
msg = ERROR_MESSAGES['UNKNOWN_TAG'].format(p[1], p.lineno(1))
self.logger.log(msg)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_tag_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from __future__ import print_function
from __future__ import unicode_literals

import sys
import unittest
from unittest import TestCase

Expand Down Expand Up @@ -95,6 +96,14 @@ def test_pacakage(self):
self.token_assert_helper(self.l.token(), 'PKG_VERF_CODE', 'PackageVerificationCode', 3)
self.token_assert_helper(self.l.token(), 'LINE', '4e3211c67a2d28fced849ee1bb76e7391b93feba (SpdxTranslatorSpdx.rdf, SpdxTranslatorSpdx.txt)', 3)

def test_unknown_tag(self):
data = '''
SomeUnknownTag: SomeUnknownValue
'''
self.l.input(data)
self.token_assert_helper(self.l.token(), 'UNKNOWN_TAG', 'SomeUnknownTag', 2)
self.token_assert_helper(self.l.token(), 'LINE', 'SomeUnknownValue', 2)

def token_assert_helper(self, token, ttype, value, line):
assert token.type == ttype
assert token.value == value
Expand Down Expand Up @@ -158,6 +167,8 @@ class TestParser(TestCase):
'FileComment: <text>Very long file</text>'
])

unknown_tag_str = 'SomeUnknownTag: SomeUnknownValue'

complete_str = '{0}\n{1}\n{2}\n{3}\n{4}'.format(document_str, creation_str, review_str, package_str, file_str)

def setUp(self):
Expand Down Expand Up @@ -207,6 +218,21 @@ def test_file(self):
assert len(spdx_file.artifact_of_project_home) == 1
assert len(spdx_file.artifact_of_project_uri) == 1

def test_unknown_tag(self):

try:
from StringIO import StringIO
except ImportError:
from io import StringIO

saved_out = sys.stdout
sys.stdout = StringIO()
document, error = self.p.parse(self.unknown_tag_str)
self.assertEqual(sys.stdout.getvalue(), 'Found unknown tag : SomeUnknownTag at line: 1\n')
sys.stdout = saved_out
assert error
assert document is not None


if __name__ == '__main__':
unittest.main()