preparefile('./Cargo.toml')
preparefile('./Cargo.lock')
preparefile('./src')
preparefile('./src/main.rs')

# run test file
b_stdout, b_stderr, b_exitcode = runcmdsafe(f'cargo run')

# convert stdout bytes to utf-8
stdout = ""
stderr = ""
try:
    stdout = b_stdout.decode('utf-8')
    stderr = b_stderr.decode('utf-8')
except:
    pass

try:
    with open('answer', 'r') as file1, open('output', 'r') as file2:
        answer = file1.read()
        output = file2.read()
        file1.close()
        file2.close()

        os.remove('output')

        assertequals(answer, output, f'{stdout}\n{stderr}')

except FileNotFoundError:
    failtest(f'{stdout}\n{stderr}')
Exemple #2
0
# Convert stdout bytes to utf-8
stdout = ""
stderr = ""
try:
    stdout = b_stdout.decode('utf-8')
    stderr = b_stderr.decode('utf-8')
except:
    pass

# Comparison with answer and output here
try:
    with open('answer', 'r') as file1, open('output', 'r') as file2:
        answer = str(file1.read())
        output = str(file2.read())
        file1.close()
        file2.close()

        # Delete output
        os.remove('output')

        # Built in tester.py function assertequals(expected, actual, info='')
        # If True, passes. If false, fails and gives expected != actual and and specified info.
        # parameters:
        # - expected(required): the answer that was expected
        # - actual(required): the output from the user's code
        # - info(optional): any additional info you want printed if it fails
        assertequals(answer, output, stdout + "\n" + stderr)

except FileNotFoundError:
    failtest(stdout + "\n" + stderr)
preparefile('./Cargo.toml')
preparefile('./Cargo.lock')
preparefile('./src')
preparefile('./src/main.rs')

# run test file
b_stdout, b_stderr, b_exitcode = runcmdsafe(f'cargo run')

# convert stdout bytes to utf-8
stdout = ""
stderr = ""
try:
    stdout = b_stdout.decode('utf-8')
    stderr = b_stderr.decode('utf-8')
except:
    pass

try:
    with open('output', 'r') as file1:
        output = file1.read()
        file1.close()

        # delete result file
        os.remove('output')

        # No answer file example
        assertequals("heo word!", output, f'{stdout}\n{stderr}')

except FileNotFoundError:
    failtest(f'{stdout}\n{stderr}')