Skip to content
Permalink
4bc58bfaca
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
70 lines (57 sloc) 1.47 KB
#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