Last active
December 21, 2018 03:12
-
-
Save DickyT/67832e13b732e679f6881f6fc016ce1e to your computer and use it in GitHub Desktop.
UMD CMSC 216 (Prof. Larry Herman) Project Auto test tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
UMD CMSC 216 Project local test tool | |
===================================== | |
This tool is ONLY being tested on Professor Larry Herman's CMSC 216 (18Fall). | |
===================================== | |
This script can be used to speed up your local project testing. | |
===================================== | |
THIS TOOL IS **NOT VIOLATING ACADEMIC INTEGRITY** IN ANY WAY. | |
PLEASE DO NOT SUBMIT THIS AS PART OF YOUR PROJECT. | |
THIS TOOL IS JUST AUTOMATIC COMPILE AND EXECUTE PUBLIC TESTS. | |
USE AT YOUR OWN RISK. | |
===================================== | |
Do this on your local *nix machine OR UMD Grace Shell | |
Tested on Grace Machine AND macOS 10.4 Mojave | |
Please ensure Python >= 3.2.3 | |
grace machine usage: | |
cd ~/216/what_ever_name_project_x | |
curl -o test.py https://git.io/fxtgj | |
python3 ./test.py | |
""" | |
__author__ = "Dicky Tsang" | |
__copyright__ = "WTFPL" | |
__license__ = "WTFPL" | |
__version__ = "0.0.1" | |
__maintainer__ = "Dicky Tsang <github.com/DickyT>" | |
__email__ = "me@idickyt.com" | |
__status__ = "Beta - For update please go to https://git.io/fxt2T" | |
import subprocess | |
import os | |
import re | |
import shutil | |
if __name__ == '__main__': | |
COMPILE_SCRIPT = 'gcc -g -ansi -pedantic-errors -Wall -Werror' \ | |
' -fstack-protector -Wshadow -lm' | |
MATCH_TEST_NUM = re.compile('public([0-9]+)\.c') | |
DEFAULT_PATH = os.path.dirname(os.path.realpath(__file__)) | |
COMPILE_PATH = os.path.join(DEFAULT_PATH, '.216_test') | |
source_files = [] | |
test_nums = [] | |
try: | |
shutil.rmtree(COMPILE_PATH) | |
except Exception: | |
pass | |
os.mkdir(COMPILE_PATH) | |
for entry in os.listdir(DEFAULT_PATH): | |
if os.path.isfile(os.path.join(DEFAULT_PATH, entry)): | |
match_list = MATCH_TEST_NUM.search(entry) | |
if match_list is not None: | |
test_num = match_list.group(1) | |
test_nums.append({ | |
'int': int(test_num), | |
'origin': test_num, | |
}) | |
else: | |
if entry.endswith('.c'): | |
source_files.append(entry) | |
test_nums.sort(key=lambda d: d['int']) | |
for test_num in test_nums: | |
source_name = 'public%s.c' % test_num['origin'] | |
correct_output_path = os.path.join(DEFAULT_PATH, 'public%s.output' % | |
test_num['origin']) | |
my_output_path = os.path.join(COMPILE_PATH, | |
'public%s.myoutput' % test_num['origin']) | |
output_exec = os.path.join(COMPILE_PATH, '%s.x' % source_name) | |
core_file_all = ' '.join(source_files) | |
try: | |
compile_cmd = '%s -o %s %s %s' % \ | |
(COMPILE_SCRIPT, output_exec, source_name, | |
core_file_all) | |
subprocess.check_output(compile_cmd, | |
stderr=subprocess.STDOUT, | |
shell=True) | |
except subprocess.CalledProcessError as e: | |
print("Test %s compile error, code=%s" % (test_num['origin'], | |
e.returncode)) | |
print("Console log -> %s" % e.output.decode('utf8')) | |
try: | |
subprocess.check_output('%s > %s' % (output_exec, | |
my_output_path), | |
stderr=subprocess.STDOUT, | |
shell=True) | |
except subprocess.CalledProcessError as e: | |
print("Test %s runtime error, code=%s" % (test_num['origin'], | |
e.returncode)) | |
print("Console log -> %s" % e.output.decode('utf8')) | |
with open(correct_output_path, 'rb+') as fp_cor: | |
with open(my_output_path, 'rb+') as fp_my: | |
correct_answer = fp_cor.read().decode('utf-8') | |
my_answer = fp_my.read().decode('utf-8') | |
if correct_answer == my_answer: | |
print('TEST %s PASSED!' % test_num['origin']) | |
else: | |
print('TEST %s NOT PASSED!' % test_num['origin']) | |
print('-----------------------------------') | |
print('-----------------------------------') |
Disclaimer
THIS TOOL DOES NOT INTENT OR KNOWINGLY VIOLATE UMD CODE OF ACADEMIC INTEGRITY
🚫 CHEATING
This script does not modify my (author) code in any way. The author can never access users' code in any way by using this script.
🚫 FABRICATION
This script does not modify users' (or anyone in the world) code in any way.
🚫 FACILITATING ACADEMIC DISHONESTY
This script does not help or attempt to help anyone in the world to cheat. This tool is just help students to run public tests faster.
🚫 PLAGIARISM
This script does not submit project for any one in the world.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UMD CMSC 216 Project local test tool
This tool is ONLY being tested on Professor Larry Herman's CMSC 216 (18Fall).
This script can be used to speed up your local project testing.
How to use
Do this on your local *nix machine OR UMD Grace Shell
Tested on Grace Machine AND macOS 10.4 Mojave
Please ensure Python >= 3.2.3
grace machine usage:
Disclaimer
THIS TOOL IS NOT VIOLATING ACADEMIC INTEGRITY IN ANY WAY.
PLEASE DO NOT SUBMIT THIS AS PART OF YOUR PROJECT.
THIS TOOL IS JUST AUTOMATIC COMPILE AND EXECUTE PUBLIC TESTS.
USE AT YOUR OWN RISK.