|
| 1 | +import pytest |
| 2 | + |
| 3 | +from vscode_task_runner.models.enums import ShellQuotingEnum |
| 4 | +from vscode_task_runner.models.options import CommandOptions |
| 5 | +from vscode_task_runner.models.properties import ( |
| 6 | + BaseCommandProperties, |
| 7 | + CommandProperties, |
| 8 | +) |
| 9 | +from vscode_task_runner.models.strings import QuotedStringConfig |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture |
| 13 | +def command_properties() -> CommandProperties: |
| 14 | + return CommandProperties( |
| 15 | + windows=BaseCommandProperties(command="Windows"), |
| 16 | + linux=BaseCommandProperties(command="Linux"), |
| 17 | + osx=BaseCommandProperties(command="OSX"), |
| 18 | + ) |
| 19 | + |
| 20 | + |
| 21 | +def test_command_properties_os_linux( |
| 22 | + linux: None, command_properties: CommandProperties |
| 23 | +) -> None: |
| 24 | + """ |
| 25 | + Ensure correct command properties are returned for Linux. |
| 26 | + """ |
| 27 | + assert command_properties.os is not None |
| 28 | + assert command_properties.os.command == "Linux" |
| 29 | + |
| 30 | + |
| 31 | +def test_command_properties_os_windows( |
| 32 | + windows: None, command_properties: CommandProperties |
| 33 | +) -> None: |
| 34 | + """ |
| 35 | + Ensure correct command properties are returned for Windows. |
| 36 | + """ |
| 37 | + assert command_properties.os is not None |
| 38 | + assert command_properties.os.command == "Windows" |
| 39 | + |
| 40 | + |
| 41 | +def test_command_properties_os_osx( |
| 42 | + osx: None, command_properties: CommandProperties |
| 43 | +) -> None: |
| 44 | + """ |
| 45 | + Ensure correct command properties are returned for OSX. |
| 46 | + """ |
| 47 | + assert command_properties.os is not None |
| 48 | + assert command_properties.os.command == "OSX" |
| 49 | + |
| 50 | + |
| 51 | +def test_command_properties_resolve_variables( |
| 52 | + linux: None, default_build_task_patch: None |
| 53 | +) -> None: |
| 54 | + """ |
| 55 | + Ensure resolve variables works for command properties. |
| 56 | + """ |
| 57 | + cp = CommandProperties( |
| 58 | + linux=BaseCommandProperties(command="${defaultBuildTask}"), |
| 59 | + ) |
| 60 | + cp.resolve_variables() |
| 61 | + |
| 62 | + assert cp.os is not None |
| 63 | + assert cp.os.command == "task1" |
| 64 | + |
| 65 | + |
| 66 | +def test_base_command_properties_resolve_variables( |
| 67 | + default_build_task_patch: None, |
| 68 | +) -> None: |
| 69 | + """ |
| 70 | + Ensure resolve variables works for base command properties. |
| 71 | + """ |
| 72 | + cp = BaseCommandProperties( |
| 73 | + command=QuotedStringConfig( |
| 74 | + value="${defaultBuildTask}", quoting=ShellQuotingEnum.escape |
| 75 | + ), |
| 76 | + options=CommandOptions(), |
| 77 | + args=[ |
| 78 | + QuotedStringConfig( |
| 79 | + value="${defaultBuildTask}", quoting=ShellQuotingEnum.escape |
| 80 | + ), |
| 81 | + "${defaultBuildTask}", |
| 82 | + ], |
| 83 | + ) |
| 84 | + cp.resolve_variables() |
| 85 | + |
| 86 | + assert cp.command == QuotedStringConfig( |
| 87 | + value="task1", quoting=ShellQuotingEnum.escape |
| 88 | + ) |
| 89 | + assert cp.args == [ |
| 90 | + QuotedStringConfig(value="task1", quoting=ShellQuotingEnum.escape), |
| 91 | + "task1", |
| 92 | + ] |
0 commit comments