Esempio n. 1
0
def test_run_pearl_bash(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    pearl_env = create_pearl_env(home_dir, {})

    script = """
    echo $PEARL_HOME
    echo $PWD
    echo $PATH
    info "Test"
    """
    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            capture_stderr=True,
                            enable_xtrace=False)

    assert result.stderr == ''

    if platform.system() == 'Darwin':
        assert result.stdout == "{}\n{}\n{}\n{}\n".format(
            home_dir, home_dir, '/usr/local/opt/gnu-sed/libexec/gnubin:'
            '/usr/local/opt/grep/libexec/gnubin:'
            '/usr/local/opt/coreutils/libexec/gnubin:' + os.environ['PATH'],
            "\x1b[0;36mTest\x1b[0m")
    elif platform.system() == 'Linux':
        assert result.stdout == "{}\n{}\n{}\n{}\n".format(
            home_dir, home_dir, os.environ['PATH'], "\x1b[0;36mTest\x1b[0m")
Esempio n. 2
0
def test_run_pearl_bash_enable_xtrace(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    pearl_env = create_pearl_env(home_dir, {})

    script = "echo hello"
    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            capture_stderr=True,
                            enable_xtrace=True)
    assert re.match(r"\+\s?echo hello\n", result.stderr) is not None
Esempio n. 3
0
def test_unlink_from_path_null_executable_path(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    pearl_env = create_pearl_env(home_dir, {})

    script = """
    unlink_from_path ""
    """
    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            check=False)
    assert result.returncode == 11
Esempio n. 4
0
def test_link_to_path_new_executable_name(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    (home_dir / 'bin').mkdir()
    pearl_env = create_pearl_env(home_dir, {})

    script = f"""
    echo "Content" > {tmp_path}/binary
    link_to_path "{tmp_path}/binary" "new_binary"
    cat $PEARL_HOME/bin/new_binary
    """

    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            check=False)
    assert result.stdout == "Content\n"
    assert result.returncode == 0
Esempio n. 5
0
def test_unlink_from_path_new_executable_name(tmp_path):
    (tmp_path / 'binary').write_text("Content")

    home_dir = create_pearl_home(tmp_path)
    (home_dir / 'bin').mkdir()
    (home_dir / 'bin/new_binary').symlink_to(tmp_path / 'binary')

    pearl_env = create_pearl_env(home_dir, {})

    assert (home_dir / 'bin/new_binary').exists()

    script = f"""
    unlink_from_path "{tmp_path}/binary" "new_binary"
    """

    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            check=False)

    assert result.returncode == 0
    assert not (home_dir / 'bin/new_binary').exists()
Esempio n. 6
0
def test_run_pearl_bash_enable_errexit(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    pearl_env = create_pearl_env(home_dir, {})

    script = """
    echo hello1
    false
    echo hello2
    """
    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            capture_stderr=True,
                            check=False,
                            enable_errexit=True)
    assert "hello1\n" == result.stdout

    result = run_pearl_bash(script,
                            pearl_env,
                            capture_stdout=True,
                            capture_stderr=True,
                            check=False,
                            enable_errexit=False)
    assert "hello1\nhello2\n" == result.stdout