Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cse3150-grading/src/asgn2/question.hpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (57 sloc)
1.47 KB
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
#ifndef __CSE3150_TESTING_ASGN2_QUESTION_H | |
#define __CSE3150_TESTING_ASGN2_QUESTION_H | |
#include <iostream> | |
#include <system_error> | |
#include <subprocess.hpp> | |
#include <internal/explode.hpp> | |
#include <internal/exists.hpp> | |
#include <optional.hpp> | |
struct Question { | |
std::string id; | |
std::string desc; | |
std::string directory() const { | |
return "./asgn2/" + this->id + "/"; | |
} | |
std::string wlist_path() const { | |
return this->directory() + "WList.cpp"; | |
} | |
std::string binary_path() const { | |
return this->directory() + "wlist"; | |
} | |
tl::optional<std::vector<std::string>> exec(const std::string& in) const { | |
if (!exists(this->binary_path())) { | |
return tl::nullopt; | |
} | |
try { | |
subprocess::popen cmd(this->binary_path(), {}); | |
cmd.stdin() << in << std::endl; | |
cmd.close(); | |
std::stringstream s; | |
s << cmd.stdout().rdbuf(); | |
std::string out = s.str(); | |
return explode(out, '\n'); | |
} catch (std::system_error) { | |
return tl::nullopt; | |
} | |
} | |
bool passes_valgrind(const std::string& in) const { | |
if (!exists(this->binary_path())) { | |
return false; | |
} | |
try { | |
subprocess::popen cmd("valgrind", { | |
"--error-exitcode=1", | |
"--leak-check=full", | |
this->binary_path() | |
}); | |
cmd.stdin() << in << std::endl; | |
cmd.close(); | |
int exit_status = cmd.wait(); | |
return exit_status != 1; | |
} catch (std::system_error) { | |
return false; | |
} | |
return false; | |
} | |
}; | |
#endif |