mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-06-26 10:54:29 +02:00
Unit Tests
- Set up initial test directory.
This commit is contained in:
parent
dd07ee6ae0
commit
dacd68b236
9 changed files with 890 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
||||||
0.9 () -
|
0.9 () -
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Project started 2014-06-08
|
||||||
|
|
||||||
------ start -----------------------------------
|
------ start -----------------------------------
|
||||||
|
|
||||||
|
|
1
test/.gitignore
vendored
Normal file
1
test/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
run_all
|
43
test/CMakeLists.txt
Normal file
43
test/CMakeLists.txt
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
include_directories (${CMAKE_SOURCE_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
${CMAKE_SOURCE_DIR}/test
|
||||||
|
${TASKSH_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
set (test_SRCS color.t)
|
||||||
|
|
||||||
|
message ("-- Configuring run_all")
|
||||||
|
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
set (TESTBLOB "./*.t")
|
||||||
|
if (CYGWIN)
|
||||||
|
set (TESTBLOB "./*.t ./*.t.exe")
|
||||||
|
endif (CYGWIN)
|
||||||
|
|
||||||
|
else (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
set (TESTBLOB "${CMAKE_SOURCE_DIR}/test/*.t ${CMAKE_BINARY_DIR}/test/*.t")
|
||||||
|
if (CYGWIN)
|
||||||
|
set (TESTBLOB "${CMAKE_SOURCE_DIR}/test/*.t ${CMAKE_BINARY_DIR}/test/*.t.exe")
|
||||||
|
endif (CYGWIN)
|
||||||
|
|
||||||
|
endif (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
configure_file (run_all.in run_all)
|
||||||
|
|
||||||
|
add_custom_target (test ./run_all --verbose
|
||||||
|
DEPENDS ${test_SRCS} tasksh_executable
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)
|
||||||
|
|
||||||
|
add_custom_target (build_tests DEPENDS ${test_SRCS}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
|
||||||
|
|
||||||
|
foreach (src_FILE ${test_SRCS})
|
||||||
|
add_executable (${src_FILE} "${src_FILE}.cpp" test.cpp)
|
||||||
|
target_link_libraries (${src_FILE} tasksh ${TASKSH_LIBRARIES})
|
||||||
|
endforeach (src_FILE)
|
||||||
|
|
||||||
|
#SET(CMAKE_BUILD_TYPE gcov)
|
||||||
|
#SET(CMAKE_CXX_FLAGS_GCOV "--coverage")
|
||||||
|
#SET(CMAKE_C_FLAGS_GCOV "--coverage")
|
||||||
|
#SET(CMAKE_EXE_LINKER_FLAGS_GCOV "--coverage")
|
196
test/color.t.cpp
Normal file
196
test/color.t.cpp
Normal file
|
@ -0,0 +1,196 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
// http://www.opensource.org/licenses/mit-license.php
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <cmake.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <Color.h>
|
||||||
|
#include <test.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int main (int argc, char** argv)
|
||||||
|
{
|
||||||
|
UnitTest t (1036);
|
||||||
|
|
||||||
|
// Ensure environment has no influence.
|
||||||
|
unsetenv ("TASKDATA");
|
||||||
|
unsetenv ("TASKRC");
|
||||||
|
|
||||||
|
// Names matched to values.
|
||||||
|
t.is ((int) Color (""), (int) Color (Color::nocolor), "'' == Color::nocolor");
|
||||||
|
t.is ((int) Color ("black"), (int) Color (Color::black), "'black' == Color::black");
|
||||||
|
t.is ((int) Color ("red"), (int) Color (Color::red), "'red' == Color::red");
|
||||||
|
t.is ((int) Color ("green"), (int) Color (Color::green), "'green' == Color::green");
|
||||||
|
t.is ((int) Color ("yellow"), (int) Color (Color::yellow), "'yellow' == Color::yellow");
|
||||||
|
t.is ((int) Color ("blue"), (int) Color (Color::blue), "'blue' == Color::blue");
|
||||||
|
t.is ((int) Color ("magenta"), (int) Color (Color::magenta), "'magenta' == Color::magenta");
|
||||||
|
t.is ((int) Color ("cyan"), (int) Color (Color::cyan), "'cyan' == Color::cyan");
|
||||||
|
t.is ((int) Color ("white"), (int) Color (Color::white), "'white' == Color::white");
|
||||||
|
|
||||||
|
// Auto upgrades.
|
||||||
|
Color c ("red on color0");
|
||||||
|
t.is ((std::string) c, "color1 on color0", "upgrade red on color0 -> color1 on color0");
|
||||||
|
|
||||||
|
c = Color ("color1 on black");
|
||||||
|
t.is ((std::string) c, "color1 on color0", "upgrade color1 on black -> color1 on color0");
|
||||||
|
|
||||||
|
c = Color ("bold red on color0");
|
||||||
|
t.is ((std::string) c, "color9 on color0", "upgrade bold red on color0 -> color9 on color0");
|
||||||
|
|
||||||
|
c = Color ("color1 on bright black");
|
||||||
|
t.is ((std::string) c, "color1 on color8", "upgrade color1 on bright black -> color1 on color8");
|
||||||
|
|
||||||
|
// Simple blending.
|
||||||
|
c = Color ("red");
|
||||||
|
c.blend (Color ("on white"));
|
||||||
|
t.is ((std::string) c, "red on white", "red + on white -> red on white");
|
||||||
|
|
||||||
|
c = Color ("bold underline red");
|
||||||
|
c.blend (Color ("on bright white"));
|
||||||
|
t.is ((std::string) c, "bold underline red on bright white", "bold underline red + on bright white -> bold underline red on bright white");
|
||||||
|
|
||||||
|
// Blending with conflicts.
|
||||||
|
c = Color ("red on white");
|
||||||
|
c.blend (Color ("on blue"));
|
||||||
|
t.is ((std::string) c, "red on blue", "red on white + on blue -> red on blue");
|
||||||
|
|
||||||
|
c = Color ("red on white");
|
||||||
|
c.blend (Color ("blue on magenta"));
|
||||||
|
t.is ((std::string) c, "blue on magenta", "red on white + blue on magenta -> blue on magenta");
|
||||||
|
|
||||||
|
// Blending with upgrades.
|
||||||
|
c = Color ("color1 on color0");
|
||||||
|
c.blend (Color ("blue"));
|
||||||
|
t.is ((std::string) c, "color4 on color0", "color1 on color0 + blue -> color4 on color0");
|
||||||
|
|
||||||
|
// Now the dumb show of every color and its code.
|
||||||
|
t.is (Color::colorize ("foo", "red"), std::string ("\033[31mfoo\033[0m"), "red -> ^[[31m");
|
||||||
|
t.is (Color::colorize ("foo", "bold red"), std::string ("\033[1;31mfoo\033[0m"), "bold red -> ^[[1;31m");
|
||||||
|
t.is (Color::colorize ("foo", "underline red"), std::string ("\033[4;31mfoo\033[0m"), "underline red -> ^[[4;31m");
|
||||||
|
t.is (Color::colorize ("foo", "underline bold red"), std::string ("\033[1;4;31mfoo\033[0m"), "underline bold red -> ^[[1;4;31m");
|
||||||
|
|
||||||
|
// 16-color foregrounds.
|
||||||
|
t.is (Color::colorize ("foo", ""), std::string ("foo"), "'' -> ''");
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", "black"), std::string ("\033[30mfoo\033[0m"), "black -> ^[[30m");
|
||||||
|
t.is (Color::colorize ("foo", "red"), std::string ("\033[31mfoo\033[0m"), "red -> ^[[31m");
|
||||||
|
t.is (Color::colorize ("foo", "green"), std::string ("\033[32mfoo\033[0m"), "green -> ^[[32m");
|
||||||
|
t.is (Color::colorize ("foo", "yellow"), std::string ("\033[33mfoo\033[0m"), "yellow -> ^[[33m");
|
||||||
|
t.is (Color::colorize ("foo", "blue"), std::string ("\033[34mfoo\033[0m"), "blue -> ^[[34m");
|
||||||
|
t.is (Color::colorize ("foo", "magenta"), std::string ("\033[35mfoo\033[0m"), "magenta -> ^[[35m");
|
||||||
|
t.is (Color::colorize ("foo", "cyan"), std::string ("\033[36mfoo\033[0m"), "cyan -> ^[[36m");
|
||||||
|
t.is (Color::colorize ("foo", "white"), std::string ("\033[37mfoo\033[0m"), "white -> ^[[37m");
|
||||||
|
|
||||||
|
// 16-color backgrounds.
|
||||||
|
t.is (Color::colorize ("foo", "on bright black"), std::string ("\033[100mfoo\033[0m"), "on bright black -> ^[[100m");
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", "on black"), std::string ("\033[40mfoo\033[0m"), "on black -> ^[[40m");
|
||||||
|
t.is (Color::colorize ("foo", "on red"), std::string ("\033[41mfoo\033[0m"), "on red -> ^[[41m");
|
||||||
|
t.is (Color::colorize ("foo", "on green"), std::string ("\033[42mfoo\033[0m"), "on green -> ^[[42m");
|
||||||
|
t.is (Color::colorize ("foo", "on yellow"), std::string ("\033[43mfoo\033[0m"), "on yellow -> ^[[43m");
|
||||||
|
t.is (Color::colorize ("foo", "on blue"), std::string ("\033[44mfoo\033[0m"), "on blue -> ^[[44m");
|
||||||
|
t.is (Color::colorize ("foo", "on magenta"), std::string ("\033[45mfoo\033[0m"), "on magenta -> ^[[45m");
|
||||||
|
t.is (Color::colorize ("foo", "on cyan"), std::string ("\033[46mfoo\033[0m"), "on cyan -> ^[[46m");
|
||||||
|
t.is (Color::colorize ("foo", "on white"), std::string ("\033[47mfoo\033[0m"), "on white -> ^[[47m");
|
||||||
|
|
||||||
|
// 256-color, basic colors.
|
||||||
|
char color [24];
|
||||||
|
char codes [64];
|
||||||
|
char description [64];
|
||||||
|
for (int i = 0; i < 256; ++i)
|
||||||
|
{
|
||||||
|
sprintf (color, "color%d", i);
|
||||||
|
sprintf (codes, "\033[38;5;%dmfoo\033[0m", i);
|
||||||
|
sprintf (description, "color%d -> ^[[38;5;%dm", i, i);
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", color), std::string (codes), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 256; ++i)
|
||||||
|
{
|
||||||
|
sprintf (color, "on color%d", i);
|
||||||
|
sprintf (codes, "\033[48;5;%dmfoo\033[0m", i);
|
||||||
|
sprintf (description, "on color%d -> ^[[48;5;%dm", i, i);
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", color), std::string (codes), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RGB Color Cube.
|
||||||
|
for (int r = 0; r < 6; ++r)
|
||||||
|
for (int g = 0; g < 6; ++g)
|
||||||
|
for (int b = 0; b < 6; ++b)
|
||||||
|
{
|
||||||
|
int code = 16 + (r*36 + g*6 + b);
|
||||||
|
sprintf (color, "rgb%d%d%d", r, g, b);
|
||||||
|
sprintf (codes, "\033[38;5;%dmfoo\033[0m", code);
|
||||||
|
sprintf (description, "rgb%d%d%d -> ^[[38;5;%dm", r, g, b, code);
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", color), std::string (codes), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int r = 0; r < 6; ++r)
|
||||||
|
for (int g = 0; g < 6; ++g)
|
||||||
|
for (int b = 0; b < 6; ++b)
|
||||||
|
{
|
||||||
|
int code = 16 + (r*36 + g*6 + b);
|
||||||
|
sprintf (color, "on rgb%d%d%d", r, g, b);
|
||||||
|
sprintf (codes, "\033[48;5;%dmfoo\033[0m", code);
|
||||||
|
sprintf (description, "on rgb%d%d%d -> ^[[48;5;%dm", r, g, b, code);
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", color), std::string (codes), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 256-color, grays.
|
||||||
|
// grey == gray.
|
||||||
|
t.is (Color::colorize ("foo", "grey0"), std::string ("\033[38;5;232mfoo\033[0m"), "grey0 -> ^[[38;5;232m");
|
||||||
|
|
||||||
|
for (int i = 0; i < 24; ++i)
|
||||||
|
{
|
||||||
|
sprintf (color, "gray%d", i);
|
||||||
|
sprintf (codes, "\033[38;5;%dmfoo\033[0m", i + 232);
|
||||||
|
sprintf (description, "gray%d -> ^[[38;5;%dm", i + 232, i + 232);
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", color), std::string (codes), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 24; ++i)
|
||||||
|
{
|
||||||
|
sprintf (color, "on gray%d", i);
|
||||||
|
sprintf (codes, "\033[48;5;%dmfoo\033[0m", i + 232);
|
||||||
|
sprintf (description, "on gray%d -> ^[[48;5;%dm", i + 232, i + 232);
|
||||||
|
|
||||||
|
t.is (Color::colorize ("foo", color), std::string (codes), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::string Color::strip (const std::string&);
|
||||||
|
t.is (Color::strip (""), "", "Color::strip '' -> ''");
|
||||||
|
t.is (Color::strip ("foo"), "foo", "Color::strip 'foo' -> 'foo'");
|
||||||
|
t.is (Color::strip ("f\033[1mo\033[0mo"), "foo", "Color::strip 'f<b>o</b>o' -> 'foo'");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
24
test/problems
Executable file
24
test/problems
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
if (open my $fh, '<', 'all.log')
|
||||||
|
{
|
||||||
|
my $test_file;
|
||||||
|
my %errors;
|
||||||
|
|
||||||
|
while (my $line = <$fh>)
|
||||||
|
{
|
||||||
|
$test_file = $1 if $line =~ /^# (\S+\.t)$/;
|
||||||
|
$errors{$test_file}++ if $line =~ /^not /;
|
||||||
|
}
|
||||||
|
|
||||||
|
close $fh;
|
||||||
|
|
||||||
|
printf "%-24s %4d\n", $_, $errors{$_}
|
||||||
|
for sort {$errors{$b} <=> $errors{$a}} keys %errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
||||||
|
|
65
test/run_all.in
Executable file
65
test/run_all.in
Executable file
|
@ -0,0 +1,65 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
rc=0
|
||||||
|
if [ x"$1" = x"--verbose" ];
|
||||||
|
then
|
||||||
|
for i in ${TESTBLOB}
|
||||||
|
do
|
||||||
|
echo '#' $i
|
||||||
|
$i > test.log 2>&1
|
||||||
|
while read LINE
|
||||||
|
do
|
||||||
|
echo "$LINE"
|
||||||
|
done < test.log
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
rc=1
|
||||||
|
fi
|
||||||
|
rm test.log
|
||||||
|
done
|
||||||
|
exit $rc
|
||||||
|
else
|
||||||
|
date > all.log
|
||||||
|
|
||||||
|
# Perl is used here to get the time in seconds
|
||||||
|
# because 'date +%s' isn't supported on Solaris.
|
||||||
|
STARTEPOCH=`perl -e 'print time'`
|
||||||
|
|
||||||
|
VRAMSTEG=`which vramsteg`
|
||||||
|
BAR=0
|
||||||
|
if [ -x "$VRAMSTEG" ]; then
|
||||||
|
BAR=1
|
||||||
|
COUNT=0
|
||||||
|
TOTAL=`ls ${TESTBLOB} | wc -l`
|
||||||
|
START=`$VRAMSTEG --now`
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in ${TESTBLOB}
|
||||||
|
do
|
||||||
|
echo '#' $i >>all.log
|
||||||
|
|
||||||
|
if [ $BAR -eq 1 ]; then
|
||||||
|
$VRAMSTEG --label 'All tests' --min 0 --max $TOTAL --current $COUNT --percentage --start $START --estimate
|
||||||
|
COUNT=`expr $COUNT + 1`
|
||||||
|
fi
|
||||||
|
|
||||||
|
$i >> all.log 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
rc=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $BAR -eq 1 ]; then
|
||||||
|
$VRAMSTEG --remove
|
||||||
|
fi
|
||||||
|
|
||||||
|
date >> all.log
|
||||||
|
|
||||||
|
ENDEPOCH=`perl -e 'print time'`
|
||||||
|
RUNTIME=`expr $ENDEPOCH - $STARTEPOCH`
|
||||||
|
|
||||||
|
printf "Pass: %5d\n" `grep -c '^ok' all.log`
|
||||||
|
printf "Fail: %5d\n" `grep -c '^not' all.log`
|
||||||
|
printf "Skipped: %5d\n" `grep -c '^skip' all.log`
|
||||||
|
printf "Runtime: %5d seconds\n" $RUNTIME
|
||||||
|
exit $rc
|
||||||
|
fi
|
55
test/template.t
Executable file
55
test/template.t
Executable file
|
@ -0,0 +1,55 @@
|
||||||
|
#! /usr/bin/env perl
|
||||||
|
################################################################################
|
||||||
|
##
|
||||||
|
## Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
|
||||||
|
##
|
||||||
|
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
## of this software and associated documentation files (the "Software"), to deal
|
||||||
|
## in the Software without restriction, including without limitation the rights
|
||||||
|
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
## copies of the Software, and to permit persons to whom the Software is
|
||||||
|
## furnished to do so, subject to the following conditions:
|
||||||
|
##
|
||||||
|
## The above copyright notice and this permission notice shall be included
|
||||||
|
## in all copies or substantial portions of the Software.
|
||||||
|
##
|
||||||
|
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
## SOFTWARE.
|
||||||
|
##
|
||||||
|
## http://www.opensource.org/licenses/mit-license.php
|
||||||
|
##
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Test::More tests => 2;
|
||||||
|
|
||||||
|
# Ensure environment has no influence.
|
||||||
|
#delete $ENV{'TASKDATA'};
|
||||||
|
#delete $ENV{'TASKRC'};
|
||||||
|
|
||||||
|
use File::Basename;
|
||||||
|
my $ut = basename ($0);
|
||||||
|
#my $rc = $ut . '.rc';
|
||||||
|
|
||||||
|
# Create the rc file.
|
||||||
|
#if (open my $fh, '>', $rc)
|
||||||
|
#{
|
||||||
|
# print $fh "data.location=.\n",
|
||||||
|
# "confirmation=off\n";
|
||||||
|
# close $fh;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Bug <id> - <description>
|
||||||
|
my $output = qx{../src/tasksh --version 2>&1};
|
||||||
|
ok ($? == 0, "$ut: version check");
|
||||||
|
like ($output, qr/tasksh version/ms, "$ut: tasksh version found");
|
||||||
|
|
||||||
|
# Cleanup.
|
||||||
|
#unlink qw(), $rc;
|
||||||
|
exit 0;
|
436
test/test.cpp
Normal file
436
test/test.cpp
Normal file
|
@ -0,0 +1,436 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
// http://www.opensource.org/licenses/mit-license.php
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <test.h>
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
UnitTest::UnitTest ()
|
||||||
|
: _planned (0)
|
||||||
|
, _counter (0)
|
||||||
|
, _passed (0)
|
||||||
|
, _failed (0)
|
||||||
|
, _skipped (0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
UnitTest::UnitTest (int planned)
|
||||||
|
: _planned (planned)
|
||||||
|
, _counter (0)
|
||||||
|
, _passed (0)
|
||||||
|
, _failed (0)
|
||||||
|
, _skipped (0)
|
||||||
|
{
|
||||||
|
std::cout << "1.." << _planned << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
UnitTest::~UnitTest ()
|
||||||
|
{
|
||||||
|
float percentPassed = 0.0;
|
||||||
|
if (_planned > 0)
|
||||||
|
percentPassed = (100.0 * _passed) / std::max (_planned, _passed + _failed + _skipped);
|
||||||
|
|
||||||
|
if (_counter < _planned)
|
||||||
|
{
|
||||||
|
std::cout << "# Only "
|
||||||
|
<< _counter
|
||||||
|
<< " tests, out of a planned "
|
||||||
|
<< _planned
|
||||||
|
<< " were run.\n";
|
||||||
|
_skipped += _planned - _counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (_counter > _planned)
|
||||||
|
std::cout << "# "
|
||||||
|
<< _counter
|
||||||
|
<< " tests were run, but only "
|
||||||
|
<< _planned
|
||||||
|
<< " were planned.\n";
|
||||||
|
|
||||||
|
std::cout << "# "
|
||||||
|
<< _passed
|
||||||
|
<< " passed, "
|
||||||
|
<< _failed
|
||||||
|
<< " failed, "
|
||||||
|
<< _skipped
|
||||||
|
<< " skipped. "
|
||||||
|
<< std::setprecision (3) << percentPassed
|
||||||
|
<< "% passed.\n";
|
||||||
|
exit (_failed > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::plan (int planned)
|
||||||
|
{
|
||||||
|
_planned = planned;
|
||||||
|
_counter = 0;
|
||||||
|
_passed = 0;
|
||||||
|
_failed = 0;
|
||||||
|
_skipped = 0;
|
||||||
|
|
||||||
|
std::cout << "1.." << _planned << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::planMore (int extra)
|
||||||
|
{
|
||||||
|
_planned += extra;
|
||||||
|
std::cout << "1.." << _planned << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::ok (bool expression, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
|
||||||
|
if (expression)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::notok (bool expression, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
|
||||||
|
if (!expression)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (bool actual, bool expected, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (actual == expected)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: "
|
||||||
|
<< expected
|
||||||
|
<< "\n# got: "
|
||||||
|
<< actual
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (size_t actual, size_t expected, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (actual == expected)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: "
|
||||||
|
<< expected
|
||||||
|
<< "\n# got: "
|
||||||
|
<< actual
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (int actual, int expected, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (actual == expected)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: "
|
||||||
|
<< expected
|
||||||
|
<< "\n# got: "
|
||||||
|
<< actual
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (double actual, double expected, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (actual == expected)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: "
|
||||||
|
<< expected
|
||||||
|
<< "\n# got: "
|
||||||
|
<< actual
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (double actual, double expected, double tolerance, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (fabs (actual - expected) <= tolerance)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: "
|
||||||
|
<< expected
|
||||||
|
<< "\n# got: "
|
||||||
|
<< actual
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (unsigned char actual, unsigned char expected, const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (actual == expected)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: "
|
||||||
|
<< expected
|
||||||
|
<< "\n# got: "
|
||||||
|
<< actual
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (
|
||||||
|
const std::string& actual,
|
||||||
|
const std::string& expected,
|
||||||
|
const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (actual == expected)
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: '"
|
||||||
|
<< expected
|
||||||
|
<< "'"
|
||||||
|
<< "\n# got: '"
|
||||||
|
<< actual
|
||||||
|
<< "'\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::is (
|
||||||
|
const char* actual,
|
||||||
|
const char* expected,
|
||||||
|
const std::string& name)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
if (! strcmp (actual, expected))
|
||||||
|
{
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< name
|
||||||
|
<< "\n# expected: '"
|
||||||
|
<< expected
|
||||||
|
<< "'"
|
||||||
|
<< "\n# got: '"
|
||||||
|
<< actual
|
||||||
|
<< "'\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::diag (const std::string& text)
|
||||||
|
{
|
||||||
|
std::string::size_type start = text.find_first_not_of (" \t\n\r\f");
|
||||||
|
std::string::size_type end = text.find_last_not_of (" \t\n\r\f");
|
||||||
|
std::cout << "# " << text.substr (start, end - start + 1) << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::pass (const std::string& text)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
++_passed;
|
||||||
|
std::cout << "ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< text
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::fail (const std::string& text)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
++_failed;
|
||||||
|
std::cout << "not ok "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< text
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void UnitTest::skip (const std::string& text)
|
||||||
|
{
|
||||||
|
++_counter;
|
||||||
|
++_skipped;
|
||||||
|
std::cout << "skip "
|
||||||
|
<< _counter
|
||||||
|
<< " - "
|
||||||
|
<< text
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
66
test/test.h
Normal file
66
test/test.h
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
// http://www.opensource.org/licenses/mit-license.php
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef INCLUDED_UNITTEST
|
||||||
|
#define INCLUDED_UNITTEST
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class UnitTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UnitTest ();
|
||||||
|
UnitTest (int);
|
||||||
|
~UnitTest ();
|
||||||
|
|
||||||
|
void plan (int);
|
||||||
|
void planMore (int);
|
||||||
|
void ok (bool, const std::string&);
|
||||||
|
void notok (bool, const std::string&);
|
||||||
|
void is (bool, bool, const std::string&);
|
||||||
|
void is (size_t, size_t, const std::string&);
|
||||||
|
void is (int, int, const std::string&);
|
||||||
|
void is (double, double, const std::string&);
|
||||||
|
void is (double, double, double, const std::string&);
|
||||||
|
void is (unsigned char, unsigned char, const std::string&);
|
||||||
|
void is (const std::string&, const std::string&, const std::string&);
|
||||||
|
void is (const char*, const char*, const std::string&);
|
||||||
|
void diag (const std::string&);
|
||||||
|
void pass (const std::string&);
|
||||||
|
void fail (const std::string&);
|
||||||
|
void skip (const std::string&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _planned;
|
||||||
|
int _counter;
|
||||||
|
int _passed;
|
||||||
|
int _failed;
|
||||||
|
int _skipped;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue