예제 #1
0
def assert_execvp_env_unchanged(p):
    cmd = '/bin/test-exec 7'
    expected = (('argc = 1', 'argv[0] = /bin/to_exec',
                 'environ[0] = TEST1=unchanged_value'))
    msg = "Wrong output of execvp function with unchanged environment"

    psh.assert_cmd(p, cmd, expected, msg)
예제 #2
0
def assert_execvp_path_searched(p):
    cmd = '/bin/test-exec 8'
    expected = (('argc = 1', 'argv[0] = to_exec',
                 'environ[0] = PATH=/bin:/sbin:/usr/bin:/usr/sbin'))
    msg = "Wrong output of execvp function with searching in PATH environment variable"

    psh.assert_cmd(p, cmd, expected, msg)
예제 #3
0
def create_testdir(p, dirname):
    # TODO: has to be changed after adding rm implementation and removing test directories
    msg = '\n'.join([
        'Wrong output when creating a test directory!',
        'Probably the directory has already been created.',
        'Try to re-build the project and run specified test second time.'
    ])

    psh.assert_cmd(p, f'mkdir {dirname}', '', msg)
예제 #4
0
def assert_kill_procs(p, pid_list):
    for pid in pid_list:
        msg = f'Wrong output when killing process with the following pid: {pid}'
        psh.assert_cmd(p, f'kill {pid}', '', msg)
    sleep(0.5)

    dead = set(pid_list) - set(proc['pid'] for proc in get_process_list(p))
    assert len(dead) == len(
        pid_list
    ), f'failed to kill {len(pid_list) - len(dead)} processes out of {len(pid_list)}'
예제 #5
0
def assert_ls_d(p):
    expected = create_ordered_pattern([
        TEST_DIR_BASIC,
    ])
    msg = 'Wrong output, when calling `ls -d tested_directory`'
    psh.assert_cmd(p, f'ls -d {TEST_DIR_BASIC}', expected, msg, is_regex=True)

    expected = create_ordered_pattern([
        '.',
    ])
    msg = 'Wrong output, when calling `ls -d` without specified directory'
    psh.assert_cmd(p, 'ls -d', expected, msg, is_regex=True)
예제 #6
0
def harness(p):
    psh.init(p)

    fname = 'etc/shells'
    expected = r'# /etc/shells: valid login shells(\r+)\n/bin/sh(\r+)\n'
    cmd = f'cat {fname}'

    psh.assert_cmd(p,
                   cmd,
                   expected,
                   msg='The /etc/shells/ file content is invalid',
                   is_regex=True)
def assert_ls_S(p):
    expected_pattern = r'.*?psh' + SEPARATOR_PATTERN + r'.*?empty_file' + SEPARATOR_PATTERN + r'.*?'
    expected_pattern = expected_pattern + psh.EOL

    psh.assert_cmd(p, 'touch /bin/empty_file', '',
                   'Wrong output when creating empty file!')

    # TODO: use only newly created files, when it will be possible to write content to a file
    psh.assert_cmd(pexpect_proc=p,
                   cmd='ls -1S /bin',
                   expected=expected_pattern,
                   msg='Wrong output, when calling `ls -1S`',
                   is_regex=True)
def assert_extralong(p):
    testdir_long = f'{ROOT_TEST_DIR}/long'
    # fname longer than standard window size: 80
    long_fname = 'loremipsum' * 9
    # there shouldn't be any new line separator in listed fname, window size should split it up if necessarily
    expected = OPTIONAL_CONTROL_CODE + long_fname + OPTIONAL_CONTROL_CODE + psh.EOL
    psh.assert_cmd(p, f'mkdir {testdir_long}', '',
                   'Wrong output when creating test directory for long file')
    psh.assert_cmd(p, f'touch {testdir_long}/{long_fname}', '',
                   f'Wrong output when creating file: {long_fname}')

    msg = "Extra long file name hasn't been printed properly!"
    psh.assert_cmd(p, f'ls {testdir_long}', expected, msg, is_regex=True)
예제 #9
0
def prepare_testdir(p, files):
    msg = 'Wrong output when creating basic directory!'
    psh.assert_cmd(p, f'mkdir {TEST_DIR_BASIC}', '', msg)
    cmd = 'touch'
    for file in files:
        if file == 'dir':
            continue
        cmd += f' {TEST_DIR_BASIC}/{file}'

    msg = 'Wrong output when creating basic test files!'
    psh.assert_cmd(p, cmd, '', msg)

    msg = 'Wrong output when creating internal test directory!'
    psh.assert_cmd(p, f'mkdir {TEST_DIR_BASIC}/dir', '', msg)
def assert_multi(p):
    files = []
    for i in range(20):
        files.append(f'file{i}')
    testdir_multi = f'{ROOT_TEST_DIR}/multi'
    psh.assert_cmd(
        p, f'mkdir {testdir_multi}', '',
        'Wrong output when creating test directory for multiple files')
    for file in files:
        psh.assert_cmd(p, f'touch {testdir_multi}/{file}', '',
                       f'Wrong output when creating {testdir_multi}/{file}')
    # assert at least 2 rows of listed files, list's content isn't checked here
    expected = r'([^\r\n]+(\r+\n)){2,}'
    msg = "Multiple files wasn't listed correctly in two lines"
    psh.assert_cmd(p, f'ls {testdir_multi}', expected, msg, is_regex=True)
예제 #11
0
def assert_errors(p):
    pid = 90
    used_pid_list = [proc["pid"] for proc in get_process_list(p)]

    # if process id is used, find next unused id
    while str(pid) in used_pid_list:
        pid = pid + 1

    msg = 'Wrong kill help message'
    psh.assert_cmd(p, 'kill', 'usage: kill <pid>', msg)
    msg = 'Wrong kill error message when passing string in argument'
    psh.assert_cmd(p, 'kill not_number',
                   'kill: could not parse process id: not_number', msg)

    # nothing should be done
    msg = 'Wrong output when killing nonexistent process'
    psh.assert_cmd(p, f'kill {pid}', '', msg)
예제 #12
0
def assert_ls_err(p):
    msg = 'Wrong error message, when trying to print nonexistent directory content'
    psh.assert_cmd(
        p, 'ls nonexistentDir',
        "ls: can't access nonexistentDir: no such file or directory", msg)
예제 #13
0
def assert_cat_err(p):
    fname = 'nonexistentFile'
    cmd = f'cat {fname}'
    statement = f'cat: {fname} no such file'

    psh.assert_cmd(p, cmd, expected=statement)
def assert_ls_t(p):
    msg_date = "Wrong output when setting date!"
    msg_touch = "Wrong output when creating file!"
    msg_mkdir = "Wrong output when creating directory!"
    date_pattern = r'\w{3},\s+\d{2}\s+\w{3}\s+\d{2}\s+\d{2}:\d{2}:\d{2}' + psh.EOL

    psh.assert_cmd(p,
                   'date -s @160000000',
                   date_pattern,
                   msg_date,
                   is_regex=True)
    psh.assert_cmd(p, f'touch {ROOT_TEST_DIR}/file_created_earliest', '',
                   msg_touch)

    psh.assert_cmd(p,
                   'date -s @162000000',
                   date_pattern,
                   msg_date,
                   is_regex=True)
    psh.assert_cmd(p, f'mkdir {ROOT_TEST_DIR}/dir_created_second', '',
                   msg_mkdir)

    psh.assert_cmd(p,
                   'date -s @164000000',
                   date_pattern,
                   msg_date,
                   is_regex=True)
    psh.assert_cmd(p, f'touch {ROOT_TEST_DIR}/file_created_last', '',
                   msg_touch)

    expected_pattern = r'.*?file_created_last.*?dir_created_second.*?file_created_earliest.*?'
    expected_pattern = expected_pattern + psh.EOL

    msg = "files are not printed in the correct order when calling `ls -t`"
    psh.assert_cmd(p,
                   f'ls -t {ROOT_TEST_DIR}',
                   expected_pattern,
                   msg,
                   is_regex=True)
예제 #15
0
def assert_cat_h(p):
    cmd = 'cat -h'
    help = ('Usage: cat [options] [files]', '  -h:  shows this help message')

    psh.assert_cmd(p, cmd, expected=help)
예제 #16
0
def harness(p):
    psh.init(p)
    psh.assert_prompt(p)

    # Simple check
    psh.assert_cmd(p, 'echo', '\r+\n', 'empty echo fail', is_regex=True)
    psh.assert_cmd(p, 'echo loremipsum', 'loremipsum', 'simple text not echoed back')
    psh.assert_cmd(p, 'echo lorem ipsum dolor ales', 'lorem ipsum dolor ales', 'multiple argument not echoed back')

    # Return value check
    psh.assert_cmd(p, 'echo $?', '0', 'last exit status was not zero')
    p.sendline("exec")  # force execution of bad command
    psh.assert_cmd(p, 'echo $?', '-22', 'last exit status was not expected -22')

    # Mingle checks
    psh.assert_cmd(p, 'echo $ lorem ipsum', ' lorem ipsum', 'bad empty $ interpretation')
    psh.assert_cmd(p, 'echo ? lorem', '? lorem', 'bad empty ? interpretation')
    psh.assert_cmd(p, 'echo lorem $? $? ipsum $?', 'lorem 0 0 ipsum 0', 'multiple return values print fail')
    psh.assert_cmd(p, 'echo lorem $ $ ipsum', 'lorem   ipsum', 'echo bad $ interpretation')
    psh.assert_cmd(p, 'echo lorem $ipsum dolor$ales', 'lorem  dolor', 'echo bad $ interpretation')
    psh.assert_cmd(p, 'echo $lorem$? ipsum', '0 ipsum', 'echo can`t print two variables consecutively')

    # Eating '"' check
    psh.assert_cmd(p, 'echo "lorem ipsum"', 'lorem ipsum', 'bad \'"\' eating')
    psh.assert_cmd(p, 'echo "lorem ""$lorem $?"', 'lorem  0', 'bad \'"\' eating')
예제 #17
0
def assert_ls_f(p, files):
    expected = create_unordered_pattern(files)
    msg = 'Wrong output, when calling `ls -f`'
    psh.assert_cmd(p, f'ls -f {TEST_DIR_BASIC}', expected, msg, is_regex=True)
예제 #18
0
def assert_ls_h(p):
    arg_help_pattern = r'(?P<help_line>\s*-[\w\s]:[ \S]+(\r+\n))+'
    expected = r'usage:(\s)ls \[options\] \[files\](\r+\n)' + arg_help_pattern
    msg = 'Wrong ls help message format'
    psh.assert_cmd(p, 'ls -h', expected, msg, is_regex=True)
예제 #19
0
def assert_ls_a(p, files):
    expected = create_ordered_pattern(sorted(files))
    msg = 'Wrong content of listed directory, when calling `ls -a`'
    psh.assert_cmd(p, f'ls -a {TEST_DIR_BASIC}', expected, msg, is_regex=True)
예제 #20
0
def assert_ls_noarg(p, files):
    expected = create_ordered_pattern(sorted(files))
    msg = 'Wrong content of listed directory, when calling ls without arguments'
    psh.assert_cmd(p, f'ls {TEST_DIR_BASIC}', expected, msg, is_regex=True)
예제 #21
0
def assert_ls_r(p, files):
    expected = create_ordered_pattern(sorted(files, reverse=True))
    msg = 'Wrong output, when calling `ls -r`'
    psh.assert_cmd(p, f'ls -r {TEST_DIR_BASIC}', expected, msg, is_regex=True)