Beispiel #1
0
def create_reference(env, test_dir, codes_and_cmd, make_new=True):
    mbuild.cmkdir(test_dir)

    if make_new:
        codes, cmd = codes_and_cmd.split(';')
        cmd_fn = os.path.join(test_dir, "cmd")
        write_file(cmd_fn, cmd + '\n')
        codes_fn = os.path.join(test_dir, "codes")
        write_file(codes_fn, codes + '\n')
    else:
        cmd = codes_and_cmd

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR', build_dir, cmd)
    print(cmd2)

    (retcode, stdout, stderr) = mbuild.run_command(cmd2, separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        for line in stdout:
            print("[STDOUT] %s" % (line))
    if stderr:
        for line in stderr:
            print("[STDERR] %s" % (line))

    write_file(os.path.join(test_dir, "retcode.reference"),
               [str(retcode) + "\n"])
    write_file(os.path.join(test_dir, "stdout.reference"), stdout)
    write_file(os.path.join(test_dir, "stderr.reference"), stderr)
Beispiel #2
0
def one_test(env,test_dir):

    cmd_fn = os.path.join(test_dir,"cmd")
    cmd = open(cmd_fn,'r').readlines()[0]

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR',build_dir,cmd)
    cmd2 = cmd2.strip()
    print(cmd2)

    (retcode, stdout,stderr) = mbuild.run_command(cmd2,separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        stdout = _prep_stream(stdout,"STDOUT")
    if stderr:
        stderr = _prep_stream(stderr,"STDERR")

    ret_match = compare_file(os.path.join(test_dir,"retcode.reference"), [ str(retcode) ])
    stdout_match = compare_file(os.path.join(test_dir,"stdout.reference"), stdout)
    stderr_match = compare_file(os.path.join(test_dir,"stderr.reference"), stderr)
    
    okay = True
    if not ret_match:
        mbuild.msgb("RETCODE MISMATCH")
        okay = False
    if not stdout_match:
        mbuild.msgb("STDOUT MISMATCH")
        okay = False
    if not stderr_match:
        mbuild.msgb("STDERR MISMATCH")
        okay = False
    print("-"*40 + "\n\n\n")
    return okay
Beispiel #3
0
def one_test(env, test_dir):

    cmd_fn = os.path.join(test_dir, "cmd")
    cmd = open(cmd_fn, 'r').readlines()[0]

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR', build_dir, cmd)
    cmd2 = cmd2.strip()
    print(cmd2)

    (retcode, stdout, stderr) = mbuild.run_command(cmd2, separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        if len(stdout) == 1:
            stdout = stdout[0].split("\n")
        if len(stdout) == 1 and stdout[0] == '':
            stdout = []
        if len(stdout) > 0 and len(stdout[-1]) == 0:
            stdout.pop()
        for line in stdout:
            print("[STDOUT] %d %s" % (len(line), line))
    if stderr:
        if len(stderr) == 1:
            stderr = stderr[0].split("\n")
        if len(stderr) == 1 and stderr[0] == '':
            stderr = []
        for line in stderr:
            print("[STDERR] %s" % (line))

    ret_match = compare_file(os.path.join(test_dir, "retcode.reference"),
                             [str(retcode)])
    stdout_match = compare_file(os.path.join(test_dir, "stdout.reference"),
                                stdout)
    stderr_match = compare_file(os.path.join(test_dir, "stderr.reference"),
                                stderr)

    okay = True
    if not ret_match:
        mbuild.msgb("RETCODE MISMATCH")
        okay = False
    if not stdout_match:
        mbuild.msgb("STDOUT MISMATCH")
        okay = False
    if not stderr_match:
        mbuild.msgb("STDERR MISMATCH")
        okay = False
    print("-" * 40 + "\n\n\n")
    return okay