Skip to content

Commit

Permalink
Avoid running solutions when there is an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dim131 committed Apr 5, 2023
1 parent c90f14e commit f8f8c53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions _includes/source_code/tester.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
make
./test_parser.out $1
sed -i 's/\r//' generated_execution.sh
bash generated_execution.sh
pout=`./test_parser.out $1`
if [[ $pout =~ "Error" ]] ; then
echo $pout
echo -e " Problem when reading the TASK file [\e[31mFAIL\e[0m]\n"
else
sed -i 's/\r//' generated_execution.sh
bash generated_execution.sh
fi

15 changes: 10 additions & 5 deletions _includes/source_code/utils/test_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ struct FileReader {

FileReader(const std::string& filename) : filename(filename) {
std::ifstream t(filename);
if (!t) {
throw ParsingException("File does not exist: " + filename);
}
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
text = str;
Expand Down Expand Up @@ -704,7 +707,7 @@ void generateFileForTasksFilterByTaskName(std::vector<Task*>& tasks, const std::
}
}
if (found == false) {
std::cout << "ERROR: No task found with the name " << task_name << "." << std::endl;
std::cout << "Error: No task found with the name " << task_name << "." << std::endl;
}
writeToFile(builder.getCode(), "generated_execution.sh");
}
Expand All @@ -731,9 +734,9 @@ void generateFileForTasksFilterByTaskAndSolution(std::vector<Task*>& tasks, cons
}
}
if (found_task == false) {
std::cout << "ERROR: No task found with the name " << task_name << "." << std::endl;
std::cout << "Error: No task found with the name " << task_name << "." << std::endl;
} else if (found_solution == false) {
std::cout << "ERROR: No solution with name " << solution_name << " found for " << task_name << "." << std::endl;
std::cout << "Error: No solution with name " << solution_name << " found for " << task_name << "." << std::endl;
}
writeToFile(builder.getCode(), "generated_execution.sh");
}
Expand Down Expand Up @@ -777,6 +780,7 @@ void deleteTasks(const std::vector<Task*>& tasks) {

int main(int argc, char *argv[]) {
std::vector<Task*> tasks;
bool found_error = false;
try {
if (argc > 1) {
std::string arg(argv[1]);
Expand All @@ -791,8 +795,9 @@ int main(int argc, char *argv[]) {
generateFileForTasks(tasks);
}
} catch (std::exception& ex) {
std::cout << ex.what() << std::endl;
// std::cout << ex.what() << std::endl;
found_error = true;
}
deleteTasks(tasks);
return 0;
return found_error;
}

0 comments on commit f8f8c53

Please sign in to comment.