Skip to content

Commit

Permalink
[UPDATE] (1.7.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-olivier committed Apr 14, 2021
1 parent 61c70ba commit 0305eaf
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 115 deletions.
Binary file modified .github/example_details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/example_diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ endif
all: $(NAME)

$(NAME): $(OBJ)
@$(CXX) -o $(NAME) $(OBJ)
@$(CXX) -o $(NAME) $(OBJ) -lpthread

install: all
@cp $(NAME) /usr/local/bin
Expand Down
45 changes: 27 additions & 18 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.6.2-blue.svg)](https://github.com/tocola/IO-TESTER/releases/tag/v1.6.2)
[![Version](https://img.shields.io/badge/IO_Tester-v1.7.0-blue.svg)](https://github.com/tocola/IO-TESTER/releases/tag/v1.7.0)
[![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 All @@ -15,20 +15,21 @@ Tested on `MacOS`, `Ubuntu`, `Fedora`, `ArchLinux`
## Installation

1. Clone this repository
2. Go to the ```IO-TESTER``` folder
2. Go to the `IO-TESTER` folder
3. Execute the following command :
```sudo make install``` (the binary will be installed at ***usr/local/bin***)
`sudo make install` (the binary will be installed at ***usr/local/bin***)

## Usage

Test files must follow this patern :
```
[Test Name] command
expected output
[END]
[END] expected return value
```
expected return value is optional (default : 0)

Here we want to test a program that takes parameters and prints them in the standard output.
Here we want to test a program that takes parameters and prints them in the standard output. We will also test some system commands
Let's create a test file :

```
Expand All @@ -37,25 +38,36 @@ Let's create a test file :
[Simple Print] python3 printer test
test
[END]
[END] 0
[Multiple Prints] python3 printer Hello World !
Hello
World
!
[END]
[END] -> 0
[Oooops] python3 printer I am bad
You
are
bad
[END] > 0
[Power] whoami
root
[END]
[ZZZzzz] sleep 10
[END]
```

Then execute `IO_Tester` with the file containing the tests as argument.

You can add `--timeout` or `-t` as first argument followed by a value in seconds as second argument to change the timeout (default : 3 sec)

You can add `--details` as final argument to display the real and the expected output in the shell when a test fails.
![example_details](https://github.com/tocola/IO-TESTER/blob/main/.github/example_details.png?raw=true)
You can add `--diff` as final argument to display the diff between the real and the expected output in VS Code when a test fails.
Expand All @@ -71,6 +83,8 @@ DESCRIPTION:
test.io file that contains functional tests
OPTIONS:
-t --timeout Change the tests timeout
must be the first argument followed by the value in seconds as second argument
-h --help Display help menu
-v --version Display actual version
-c --changelog Display the changelog
Expand All @@ -86,29 +100,24 @@ RETURN VALUE:

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

## Build Tips
If you want to uninstall IO-Tester :
```make uninstall```

`make uninstall`

If you just want to get the binary without installing :
```make```

`make`

If you want to remove all objects files :
```make clean```

`make clean`

If you want to remove all objects files and the binary :
```make fclean```


`make fclean`

## Contributors

- [Benjamin Reigner](https://github.com/Breigner01)
- [Alexandre Chetrit](https://github.com/chetrit)
- [Coline Seguret](https://github.com/Cleopha)
- [Coline Seguret](https://github.com/Cleopha)
13 changes: 11 additions & 2 deletions examples/test.io
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
[Simple Print] python3 printer test
test

[END]
[END] 0

[Multiple Prints] python3 printer Hello World !
Hello
World
!

[END]
[END] -> 0

[Oooops] python3 printer I am bad
You
are
bad

[END] > 0

[Power] whoami
root

[END]

[ZZZzzz] sleep 10

[END]
28 changes: 11 additions & 17 deletions src/Diff.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
#include "IO_Tester.hpp"
#include <unistd.h>

void IOTester::VSCodeDiff(const Test &t, const Utils::CMD &c)
void IOTester::VSCodeDiff(const Test &t, const std::string &output)
{
std::string filename1 = "\"/tmp/GOT(" + t.m_name + ")\"";
std::string filename2 = "\"/tmp/EXPECTED(" + t.m_name + ")\"";
std::string s1 = "echo \"" + c.output + "\" > " + filename1;
std::string s1 = "echo \"" + output + "\" > " + filename1;
std::string s2 = "echo \"" + t.m_output + "\" > " + filename2;

system(std::string(s1 + " ; " + s2).c_str());
system(std::string(VSCodePath + filename1 + " " + filename2).c_str());
}

void IOTester::checkVSCodeBin()
bool IOTester::checkVSCodeBin()
{
#ifdef __APPLE__
if (access("/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code", X_OK) != -1) {
m_VSCodeBin = OK;
return;
}
m_VSCodeBin = KO;
if (access("/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code", X_OK) != -1)
return true;
return false;
#else
char* env_p = std::getenv("PATH");
if (env_p == NULL) {
m_VSCodeBin = KO;
return;
}
if (env_p == NULL)
return false;
auto PATHList = Utils::string_to_vector(env_p, ':');

for (auto &path : PATHList) {
if (access((std::string(path + "/code").c_str()), X_OK) != -1) {
m_VSCodeBin = OK;
return;
}
if (access((std::string(path + "/code").c_str()), X_OK) != -1)
return true;
}
m_VSCodeBin = KO;
return false;
#endif
}
18 changes: 17 additions & 1 deletion src/ErrorHandling.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ErrorHandling.hpp"
#include "Utils.hpp"
#include <iostream>
#include <algorithm>

enum CheckStatus {Input, Output};

Expand All @@ -12,6 +14,8 @@ void ErrorHandling::Help(const char *bin, int returnValue)
std::cout << "\ttest.io\t\tfile that contains functional tests\n" << std::endl;

std::cout << "OPTIONS:" << std::endl;
std::cout << "\t-t --timeout\tChange the tests timeout" << std::endl;
std::cout << "\t\t\tmust be the first argument followed by the value in seconds as second argument" << std::endl;
std::cout << "\t-h --help\tDisplay help menu" << std::endl;
std::cout << "\t-v --version\tDisplay actual version" << std::endl;
std::cout << "\t-c --changelog\tDisplay the changelog" << std::endl;
Expand Down Expand Up @@ -64,8 +68,20 @@ std::vector<std::string> ErrorHandling::CheckFile(char *path)
status = Output;
}
else if (status == Output) {
if (line == "[END]")
if (line.find("[END]") == 0) {
status = Input;
line.erase(remove_if(line.begin(), line.end(), isspace), line.end());
std::string ret_val = line.substr(5);
if (!ret_val.empty() and ret_val[0] == '>')
ret_val.erase(ret_val.begin());
else if (ret_val.size() >= 2 and ret_val[0] == '-' and ret_val[1] == '>') {
ret_val.erase(ret_val.begin());
ret_val.erase(ret_val.begin());
}
if (ret_val.empty())
ret_val.push_back('0');
line = "[END]" + ret_val;
}
}
}
if (status == Output)
Expand Down
Loading

0 comments on commit 0305eaf

Please sign in to comment.