def test_shell_cmd_to_ast_errors(some_context):
    with pytest.raises(VirtSyntaxError) as err:
        tuple(shell_cmd_to_ast('false\n', some_context))
    assert some_context == err.value.context
    with pytest.raises(VirtSyntaxError) as err:
        tuple(shell_cmd_to_ast('false\ntrue\n', some_context))
    assert some_context == err.value.context
def test_shell_cmd_to_ast(some_context):
    script = """
        # shell comment
        echo '# ast comment'
        echo ast_command arg1:arg2:arg3
        echo given_file_is "$VIRT_COMMAND_FILE"
        echo given_line_is "$VIRT_COMMAND_LINE"
    """
    expected = tuple(lines_to_ast(
        (
            '# ast comment',
            'ast_command arg1:arg2:arg3',
            'given_file_is {0}'.format(some_context.file),
            'given_line_is {0}'.format(some_context.line),
        ),
        context_file='script<{0} ({1})>'.format(*some_context),
        context_nest_in=some_context,
    ))
    os.environ['VIRT_COMMAND_FILE'] = 'was_not_changed'
    os.environ['VIRT_COMMAND_LINE'] = 'not_changed_either'
    result = tuple(shell_cmd_to_ast(script, run_context=some_context))
    assert expected == result
    assert os.environ['VIRT_COMMAND_FILE'] == 'was_not_changed'
    assert os.environ['VIRT_COMMAND_LINE'] == 'not_changed_either'