-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Test that command and arguments fields are handled correctly. - Test that we can identify which commands we can/should emulate. Signed-off-by: John Pennycook <john.pennycook@intel.com>
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (C) 2019-2024 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (C) 2019-2024 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import unittest | ||
|
||
from codebasin import CompileCommand | ||
|
||
|
||
class TestCompileCommand(unittest.TestCase): | ||
""" | ||
Test CompileCommand class. | ||
""" | ||
|
||
def test_commands_and_arguments(self): | ||
"""Check commands and arguments are not both None""" | ||
|
||
with self.assertRaises(ValueError): | ||
CompileCommand("file.cpp", command=None, arguments=None) | ||
|
||
with self.assertRaises(ValueError): | ||
instance = { | ||
"file": "file.cpp", | ||
} | ||
CompileCommand.from_json(instance) | ||
|
||
def test_command_to_arguments(self): | ||
"""Check commands convert to arguments""" | ||
command = CompileCommand("file.cpp", command="c++ file.cpp") | ||
self.assertEqual(command.arguments, ["c++", "file.cpp"]) | ||
|
||
instance = { | ||
"file": "file.cpp", | ||
"command": "c++ file.cpp", | ||
} | ||
command = CompileCommand.from_json(instance) | ||
self.assertEqual(command.arguments, ["c++", "file.cpp"]) | ||
|
||
def test_arguments_to_command(self): | ||
"""Check arguments convert to command""" | ||
command = CompileCommand("file.cpp", arguments=["c++", "file.cpp"]) | ||
self.assertEqual(str(command), "c++ file.cpp") | ||
|
||
instance = { | ||
"file": "file.cpp", | ||
"arguments": [ | ||
"c++", | ||
"file.cpp", | ||
], | ||
} | ||
command = CompileCommand.from_json(instance) | ||
self.assertEqual(str(command), "c++ file.cpp") | ||
|
||
def test_empty_command(self): | ||
"""Check empty commands are not supported""" | ||
command = CompileCommand("file.cpp", command="") | ||
self.assertFalse(command.is_supported()) | ||
|
||
def test_link_command(self): | ||
"""Check link commands are not supported""" | ||
command = CompileCommand("file.o", command="c++ -o a.out file.o") | ||
self.assertFalse(command.is_supported()) | ||
|
||
def test_valid_command(self): | ||
"""Check valid commands are supported""" | ||
command = CompileCommand("file.cpp", command="c++ file.cpp") | ||
self.assertTrue(command.is_supported()) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |