def test(run_local, bash_config): """Test (run) student's code without evaluating it for correctness. This function should store the output of the student's code in files.STUDENT_OUT. It is recommended that you use util.run_program() to pipe the results of executing the student's code into files.STUDENT_OUT (stdout) and files.STUDENT_ERR (stderr). Args: run_local (bool): flag indicating if test is being run locally bash_config (string): bash commands for configuing environment Raises: Any errors stemming from the exection of the program(s) required to run the student's code. """ # create script for running student's code run_student_bash = '#!/bin/bash\n' + bash_config + 'node StudentMain.js' with open('student_runner.sh', 'w') as f: f.write(run_student_bash) os.chmod('./student_runner.sh', '0755') try: util.run_program(['./student_runner.sh'], files.STUDENT_OUT, files.STUDENT_ERR) except: raise finally: os.remove('student_runner.sh')
def pre_evaluate(for_submission=True): """ Compile test/submit code. Args: for_submission (bool): Whether or not this is for submission or just test run. Submission will compile against submitMain.cpp, while testing compiles against testMain.cpp. """ # call the compile shell script os.chmod('./compile.sh', '0755') util.run_program(['./compile.sh', for_submission], '.tmp/compile-out.txt', '.tmp/compile-err.txt')
def test(run_local, bash_config): """Test (run) student's code without evaluating it for correctness. This function should store the output of the student's code in files.STUDENT_OUT. It is recommended that you use util.run_program() to pipe the results of executing the student's code into files.STUDENT_OUT (stdout) and files.STUDENT_ERR (stderr). Args: run_local (bool): flag indicating if test is being run locally bash_config (string): bash commands for configuing environment Raises: Any errors stemming from the exection of the program(s) required to run the student's code. """ try: util.run_program(['swift', 'StudentMain.swift'], files.STUDENT_OUT, files.STUDENT_ERR) except: raise
def submit(run_local, bash_config): """Evaluate the student's code by testing it for correctness. This function should store the output of evaluating the student's code in files.RESULTS_OUT. It is recommended that you use util.run_program() to pipe the results of evaluating the student's code into files.RESULTS_OUT (stdout) and files.RESULTS_ERR (stderr). Args: run_local (bool): flag indicating if test is being run locally bash_config (string): bash commands for configuing environment Raises: Any errors stemming from the exection of the program(s) required to evalute the student's code. """ # create script for running student's code run_student_bash = '#!/bin/bash\n' + bash_config + 'node StudentMain.js' with open('student_runner.sh', 'w') as f: f.write(run_student_bash) os.chmod('./student_runner.sh', '0755') # create script for running student's code + our testing code run_swizzled_bash = '#!/bin/bash\n' + bash_config + 'node SwizzledMain.js' with open('swizzled_runner.sh', 'w') as f: f.write(run_swizzled_bash) os.chmod('./swizzled_runner.sh', '0755') try: # generate swizzled main filenames = [ 'SwizzleInclude.js', 'SwizzleBefore.js', 'StudentMain.js', 'SwizzleAfter.js' ] errors = [] with open('SwizzledMain.js', 'w') as outfile: for fname in filenames: try: with open(fname) as infile: outfile.write(infile.read()) except IOError: errors.append('file ' + fname + ' not found') else: outfile.write('\n') if len(errors) > 0: # pipe errors to file util.run_program(['echo', str(errors)], files.RESULTS_ERR, files.RESULTS_ERR) else: # run swizzled main util.run_program(['./swizzled_runner.sh'], files.RESULTS_OUT, files.RESULTS_ERR) # run student main (for extra debugging) util.run_program(['./student_runner.sh'], files.STUDENT_OUT, files.STUDENT_ERR) except: raise finally: os.remove('swizzled_runner.sh') os.remove('student_runner.sh')
def submit(run_local, bash_config): """Evaluate the student's code by testing it for correctness. This function should store the output of evaluating the student's code in files.RESULTS_OUT. It is recommended that you use util.run_program() to pipe the results of evaluating the student's code into files.RESULTS_OUT (stdout) and files.RESULTS_ERR (stderr). Args: run_local (bool): flag indicating if test is being run locally bash_config (string): bash commands for configuing environment Raises: Any errors stemming from the exection of the program(s) required to evalute the student's code. """ # create script for execution if run_local: run_student_bash = '#!/bin/bash\n' + bash_config + 'node StudentMain.js' run_swizzled_bash = '#!/bin/bash\n' + bash_config + 'mocha --reporter json SwizzledMain.js' else: run_student_bash = '''#!/bin/bash export NVM_DIR=/usr/nvm source /opt/nvm/nvm.sh node StudentMain.js ''' run_swizzled_bash = """#!/bin/bash # Launches Mocha with the default NVM version of Node.js. export NVM_DIR=/usr/nvm . /opt/nvm/nvm.sh NODE_VERSION=$(nvm current) NODE_ROOT=${NVM_DIR}/versions/node/${NODE_VERSION} # Put global modules on the Node.js path export NODE_PATH=${NODE_ROOT}/lib/node_modules exec mocha --reporter json SwizzledMain.js """ with open('student_runner.sh', 'w') as f: f.write(run_student_bash) os.chmod('./student_runner.sh', 0755) with open('swizzled_runner.sh', 'w') as f: f.write(run_swizzled_bash) os.chmod('./swizzled_runner.sh', 0755) # generate files, run scripts try: # generate swizzled main filenames = ['SwizzleInclude.js', 'SwizzleBefore.js', 'StudentMain.js', 'SwizzleAfter.js'] errors = [] with open('SwizzledMain.js', 'w') as outfile: for fname in filenames: try: with open(fname) as infile: outfile.write(infile.read()) except IOError: errors.append('file ' + fname + ' not found') else: outfile.write('\n') if len(errors) > 0: # pipe errors to file util.run_program(['echo', str(errors)], files.RESULTS_ERR, files.RESULTS_ERR) else: # run swizzled main util.run_program(['./swizzled_runner.sh'], files.RESULTS_OUT, files.RESULTS_ERR) # run student main (for extra debugging) util.run_program(['./student_runner.sh'], files.STUDENT_OUT, files.STUDENT_ERR) except: raise finally: os.remove('swizzled_runner.sh') os.remove('student_runner.sh')
def evaluate(): """ Actually run the compiled code. """ util.run_program(['./main.o'], files.STUDENT_OUT, files.STUDENT_ERR)