def get_command_to_run(filename): (directory, name, extension) = get_file_tuple(filename) output_file = directory + '/' + name + '.out' command_run = output_file test_file = directory + '/' + name + '.input' if os.path.exists(test_file): command_run += ' < ' + test_file return command_run
def get_command_for_compilation(filename): (directory, name, extension) = get_file_tuple(filename) output_filename = directory + '/' + name + '.out' command = EXECUTABLE_GCC + ' ' + \ get_gcc_flags() + \ ' -o ' + output_filename + \ ' ' + filename return command
def test_get_file_tuple_splits_properly(self): dummy_directory = "dummy_directory" (directory, name, extension) = get_file_tuple(dummy_directory + '/' + self.filename_cpp) self.assertIn(dummy_directory, directory) self.assertEqual(name, 'foobar') self.assertEqual(extension, 'cpp')
def build_and_run_file(filename): ''' Builds and runs the filename specified according to the extension PARAM filename: name of file to build and run ''' (directory, name, extension) = get_file_tuple(filename) if extension == 'c': print(" = = = = = = ", YELLOW, "GCC: Compiling " + filename + " file", \ RESET, " = = = = = =\n") compiler = Compiler(filename) out = compiler.compile() if out != 0: print('Error while compiling. Code:', out, 'Please retry.') return out print("") out = compiler.run() return out elif extension == 'cpp': print(" = = = = = = ", YELLOW, "GPP: Compiling " + filename + " file", \ RESET, " = = = = = =\n") compiler = Compiler(filename) out = compiler.compile() if out != 0: print('Error while compiling. Code:', out, 'Please retry.') return out print("") out = compiler.run() return out elif extension == 'py': print(" = = = = = = ", YELLOW, "PYTHON: Executing " + filename + " file", \ RESET, " = = = = = =\n") command_run = EXECUTABLE_PYTHON + " " + filename test_file = directory + "/" + name + ".input" if os.path.exists(test_file): command_run += " < " + test_file return perform_system_command(command_run) elif extension == 'java': command = EXECUTABLE_JAVAC + ' ' + filename perform_system_command(command) command_run = EXECUTABLE_JAVA + ' ' + name test_file = directory + "/" + name + ".input" if os.path.exists(test_file): command_run += " < " + test_file return perform_system_command(command_run) else: print("Language yet not supported") return -1
def memory_test(filename): ''' make sure filename.test exits and call for valgrind(choose to perform memory test) PARAM filename: name of file to run test on ''' (directory, name, extension) = get_file_tuple(filename) # if not c or cpp files, no mem test to run if extension != 'c' and extension != 'cpp': return test_file = name + ".test" print("Test file: " + test_file) # print(len(args), args) if not os.path.isfile(test_file): print("Test file not found") return valgrind_test(test_file)