Skip to content

Commit

Permalink
[UPDATE] (1.7.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-olivier committed Apr 21, 2021
1 parent 0305eaf commit b088a4a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IO-Tester
[![Version](https://img.shields.io/badge/IO_Tester-v1.7.0-blue.svg)](https://github.com/tocola/IO-TESTER/releases/tag/v1.7.0)
[![Version](https://img.shields.io/badge/IO_Tester-v1.7.1-blue.svg)](https://github.com/tocola/IO-TESTER/releases/tag/v1.7.1)
[![MIT license](https://img.shields.io/badge/License-MIT-orange.svg)](https://github.com/tocola/IO-TESTER/blob/main/LICENSE)
[![CPP Version](https://img.shields.io/badge/C++-17-darkgreen.svg)](https://isocpp.org/)

Expand Down Expand Up @@ -100,7 +100,7 @@ RETURN VALUE:

You can also run multiple test files at once :
```sh
IO_Tester --timeout 5 test1.io test2.io test3.io --diff
IO_Tester --timeout 0.05 test1.io test2.io test3.io --diff
```

## Build Tips
Expand Down
12 changes: 6 additions & 6 deletions src/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ void ErrorHandling::Help(const char *bin, int returnValue)
void ErrorHandling::isInput(const std::string &line)
{
if (line[0] != '[')
Utils::my_exit(84, "Parsing Error at line :\n" + line);
Utils::my_exit(84, "parsing error at line :\n" + line);
if (line.find(']') == std::string::npos)
Utils::my_exit(84, "Parsing Error at line :\n" + line);
Utils::my_exit(84, "parsing error at line :\n" + line);
if (line.find(']') == line.size() - 1 || line.find(']') == 1)
Utils::my_exit(84, "Parsing Error at line :\n" + line);
Utils::my_exit(84, "parsing error at line :\n" + line);
}

void ErrorHandling::checkIsEmpty(const std::vector<std::string> &file)
{
if (file.empty())
Utils::my_exit(84, "Error : File is Empty");
Utils::my_exit(84, "error : file is empty");
for (auto &line : file) {
if (!line.empty())
return;
}
Utils::my_exit(84, "Error : File is Empty");
Utils::my_exit(84, "error : file is empty");
}

std::vector<std::string> ErrorHandling::CheckFile(char *path)
Expand Down Expand Up @@ -85,6 +85,6 @@ std::vector<std::string> ErrorHandling::CheckFile(char *path)
}
}
if (status == Output)
Utils::my_exit(84, "Parsing Error at the last line");
Utils::my_exit(84, "parsing error at the last line");
return file;
}
15 changes: 7 additions & 8 deletions src/IO_Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
void IOTester::Version()
{
std::cout << "IO_Tester (" << VERSION << ")" << std::endl;
std::cout << "Written by Martin OLIVIER, Student at {EPITECH} Paris" << std::endl;
std::cout << "Written by Martin OLIVIER, student at {EPITECH} Paris" << std::endl;
exit(0);
}

IOTester::IOTester(int ac, char **av) :
m_passed(0), m_failed(0), m_crashed(0), m_timeout(0), m_position(0), m_details(NO), m_return(EXIT_SUCCESS), m_timeout_value(3)
m_passed(0), m_failed(0), m_crashed(0), m_timeout(0), m_position(0), m_details(NO), m_return(EXIT_SUCCESS), m_timeout_value(3.0)
{
int i = 1;
if (ac < 2)
ErrorHandling::Help(av[0], 84);
if (std::string_view(av[1]) == "-t" or std::string_view(av[1]) == "--timeout") {
if (ac == 2)
ErrorHandling::Help(av[0], 84);
try {m_timeout_value = std::stol(av[2]);}
try {m_timeout_value = std::stof(av[2]);}
catch (...) {Utils::my_exit(84, "Invalid timeout argument : IO_Tester " + std::string(av[1]) + " <time in seconds> test.io");}
if (m_timeout_value < 0)
Utils::my_exit(84, "Invalid timeout argument : IO_Tester " + std::string(av[1]) + " <time in seconds> test.io");
Expand Down Expand Up @@ -118,7 +118,7 @@ Test IOTester::getTestData()
t.m_output += m_file[m_position] + '\n';
std::string ret_val = m_file[m_position].substr(5);
try {t.m_return_value = std::stoi(ret_val);}
catch (...) {Utils::my_exit(84, "Error : bad expected return value : " + ret_val);}
catch (...) {Utils::my_exit(84, "error : bad expected return value : " + ret_val);}
m_position++;
if (!t.m_output.empty())
t.m_output.pop_back();
Expand Down Expand Up @@ -194,10 +194,9 @@ void IOTester::comparator(Test t)
int ret = Test::NIL;
std::thread th(compute, t, pid, std::ref(ret), m_details);

std::chrono::system_clock::time_point chrono
= std::chrono::system_clock::now() + std::chrono::seconds(m_timeout_value);
std::chrono::system_clock::time_point deadline = std::chrono::system_clock::now() + std::chrono::microseconds(static_cast<int>(m_timeout_value * 1000000));
while (true) {
if (std::chrono::system_clock::now() >= chrono)
if (std::chrono::system_clock::now() >= deadline)
break;
if (ret != Test::NIL)
break;
Expand All @@ -215,7 +214,7 @@ void IOTester::comparator(Test t)
m_timeout++;
}
else if (ret == Test::ERROR)
Utils::my_exit(84, "Pipe Error, Exiting...");
Utils::my_exit(84, "pipe error, exiting...");
}

void IOTester::printFinalResults() const
Expand Down
4 changes: 2 additions & 2 deletions src/IO_Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <vector>

#define VERSION "1.7.0"
#define VERSION "1.7.1"

#ifdef __APPLE__
#define VSCodePath "\"/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code\" --diff "
Expand Down Expand Up @@ -57,6 +57,6 @@ class IOTester
size_t m_position;
Details m_details;
bool m_return;
long m_timeout_value;
float m_timeout_value;
std::vector<std::string> m_file;
};
3 changes: 3 additions & 0 deletions src/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ void IOTester::Changelog()
"(1.7.0)",
"> [ADD] Timeout",
"> [ADD] Expected Return Value",
"(1.7.1)",
"> [ADD] Timeout value can be a float",
"> [FIX] Better error messages",
};
std::cout << "[CHANGELOG] :" << std::endl;
for (auto line : changelog)
Expand Down

0 comments on commit b088a4a

Please sign in to comment.