ADD: test bash script.

main
bog 2023-09-11 14:27:44 +02:00
parent 0795eb5d9f
commit 690122ea4a
2 changed files with 96 additions and 40 deletions

36
examples/run.sh Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
OK=0
TOTAL=0
for file in `find . -name "*.gri" -exec basename {} \;`
do
echo -en "\e[34m$file ... \e[0m"
MSG="$(grino $file 2>&1 > /dev/null)"
RES=$?
if [ "$RES" == "0" ]
then
echo -e "ok"
OK=$(($OK + 1))
else
echo "ko"
echo -e "\t\e[31m$MSG\e[0m"
fi
TOTAL=$(($TOTAL + 1))
done
echo
if [ $OK -eq $TOTAL ]
then
echo -e "\e[32m=== $OK/$TOTAL tests passed ! ===\e[0m"
exit 0
fi
FAILURE=$(($TOTAL - $OK))
echo -e "\e[31m=== $FAILURE/$TOTAL tests failed ===\e[0m"
exit -1

View File

@ -11,49 +11,8 @@
#include "src/SymTable.hpp" #include "src/SymTable.hpp"
#include "Loader.hpp" #include "Loader.hpp"
int main(int argc, char** argv) void run(char** argv, bool debug_mode)
{ {
bool debug_mode = false;
static struct option options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"debug", no_argument, 0, 'd'},
{0, 0, 0, 0}
};
int option_index = 0;
int c = getopt_long(argc, argv, "hvd", options, &option_index);
switch (c)
{
case 'h': {
std::cout << "Usage: grino [OPTION]... source" << std::endl;
std::cout << "OPTIONS:" << std::endl;
std::cout << "\t" << "-d, --debug, "
<< "activate debug mode" << std::endl;
std::cout << "\t" << "-h, --help, "
<< "show this message" << std::endl;
std::cout << "\t" << "-v, --version, "
<< "show grino version" << std::endl;
exit(0);
} break;
case 'v': {
std::cout << "grino version: " << GRINO_VERSION << std::endl;
std::cout << "License: " << "GPLv3 or later (see LICENSE)"<< std::endl;
exit(0);
} break;
case 'd': {
debug_mode = true;
} break;
}
if (optind < argc)
{
std::string source; std::string source;
{ {
std::ifstream file { argv[optind] }; std::ifstream file { argv[optind] };
@ -99,6 +58,67 @@ int main(int argc, char** argv)
std::cout << "--- stack ---" << std::endl; std::cout << "--- stack ---" << std::endl;
std::cout << vm.string() << std::endl; std::cout << vm.string() << std::endl;
} }
}
int main(int argc, char** argv)
{
bool debug_mode = false;
static struct option options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"debug", no_argument, 0, 'd'},
{0, 0, 0, 0}
};
int option_index = 0;
int c = getopt_long(argc, argv, "hvd", options, &option_index);
switch (c)
{
case 'h': {
std::cout << "Usage: grino [OPTION]... source" << std::endl;
std::cout << "OPTIONS:" << std::endl;
std::cout << "\t" << "-d, --debug, "
<< "activate debug mode" << std::endl;
std::cout << "\t" << "-h, --help, "
<< "show this message" << std::endl;
std::cout << "\t" << "-v, --version, "
<< "show grino version" << std::endl;
exit(0);
} break;
case 'v': {
std::cout << "grino version: " << GRINO_VERSION << std::endl;
std::cout << "License: " << "GPLv3 or later (see LICENSE)"<< std::endl;
exit(0);
} break;
case 'd': {
debug_mode = true;
} break;
}
if (optind < argc)
{
if (debug_mode)
{
run(argv, debug_mode);
}
else
{
try
{
run(argv, debug_mode);
}
catch(std::exception const& err)
{
std::cerr << err.what() << std::endl;
exit(-1);
}
}
} }
return 0; return 0;