mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-06-26 10:54:29 +02:00
Unit Tests
- Now build and run the color tests.
This commit is contained in:
parent
eb915bd054
commit
1647ca6b4d
10 changed files with 336 additions and 9 deletions
|
@ -3,7 +3,8 @@ include_directories (${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
${TASKSH_INCLUDE_DIRS})
|
${TASKSH_INCLUDE_DIRS})
|
||||||
|
|
||||||
set (tasksh_SRCS Color.cpp Color.h)
|
set (tasksh_SRCS Color.cpp Color.h
|
||||||
|
text.cpp text.h)
|
||||||
|
|
||||||
add_executable (tasksh_executable main.cpp ${task_SRCS})
|
add_executable (tasksh_executable main.cpp ${task_SRCS})
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <main.h>
|
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
|
|
113
src/eng-USA.h
Normal file
113
src/eng-USA.h
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// This file contains all the strings that should be localized. If a string is
|
||||||
|
// *not* in this file, then either:
|
||||||
|
// (a) it should not be localized, or
|
||||||
|
// (b) you have found a bug - please report it
|
||||||
|
//
|
||||||
|
// Strings that should be localized:
|
||||||
|
// - text output that the user sees
|
||||||
|
//
|
||||||
|
// Strings that should NOT be localized:
|
||||||
|
// - .taskrc configuration variable names
|
||||||
|
// - command names
|
||||||
|
// - extension function names
|
||||||
|
// - certain literals associated with parsing
|
||||||
|
// - debug strings
|
||||||
|
// - attribute names
|
||||||
|
// - modifier names
|
||||||
|
// - logical operators (and, or, xor)
|
||||||
|
//
|
||||||
|
// Rules:
|
||||||
|
// - Localized strings should not in general contain leading or trailing
|
||||||
|
// white space, including \n, thus allowing the code to compose strings.
|
||||||
|
// - Retain the tense of the original string.
|
||||||
|
// - Retain the same degree of verbosity of the original string.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Translators:
|
||||||
|
// 1. Copy this file (eng-USA.h) to a new file with the target locale as the
|
||||||
|
// file name. Using German as an example, do this:
|
||||||
|
//
|
||||||
|
// cp eng-USA.h deu-DEU.h
|
||||||
|
//
|
||||||
|
// 2. Modify all the strings below.
|
||||||
|
// i.e. change "Unknown error." to "Unbekannter Fehler.".
|
||||||
|
//
|
||||||
|
// 3. Add your new translation to the task.git/src/i18n.h file, if necessary,
|
||||||
|
// by inserting:
|
||||||
|
//
|
||||||
|
// #elif PACKAGE_LANGUAGE == LANGUAGE_DEU_DEU
|
||||||
|
// #include <deu-DEU.h>
|
||||||
|
//
|
||||||
|
// 4. Add your new language to task.git/CMakeLists.txt, making sure that
|
||||||
|
// number is unique:
|
||||||
|
//
|
||||||
|
// set (LANGUAGE_DEU_DEU 3)
|
||||||
|
//
|
||||||
|
// 5. Add your new language to task.git/cmake.h.in:
|
||||||
|
//
|
||||||
|
// #define LANGUAGE_DEU_DEU ${LANGUAGE_DEU_DEU}
|
||||||
|
//
|
||||||
|
// 6. Build your localized Taskwarrior with these commands:
|
||||||
|
//
|
||||||
|
// cd task.git
|
||||||
|
// cmake -D LANGUAGE=3 .
|
||||||
|
// make
|
||||||
|
//
|
||||||
|
// 7. Submit your translation to support@taskwarrior.org, where it will be
|
||||||
|
// shared with others.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef INCLUDED_STRINGS
|
||||||
|
#define INCLUDED_STRINGS
|
||||||
|
|
||||||
|
// Note that for English, the following two lines are not displayed. For all
|
||||||
|
// other localizations, these lines will appear in the output of the 'version'
|
||||||
|
// and 'diagnostics' commands.
|
||||||
|
//
|
||||||
|
// DO NOT include a copyright in the translation.
|
||||||
|
//
|
||||||
|
#define STRING_LOCALIZATION_DESC "English localization"
|
||||||
|
#define STRING_LOCALIZATION_AUTHOR "Translated into English by A. Person."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
#define STRING_UNKNOWN_ERROR "Unknown error."
|
||||||
|
|
||||||
|
// Color
|
||||||
|
#define STRING_COLOR_UNRECOGNIZED "The color '{1}' is not recognized."
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
66
src/i18n.h
Normal file
66
src/i18n.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
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Strings that should be localized:
|
||||||
|
// - All text output that the user sees or types
|
||||||
|
//
|
||||||
|
// Strings that should NOT be localized:
|
||||||
|
// - ./taskrc configuration variable names
|
||||||
|
// - certain literals associated with parsing
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef INCLUDED_I18N
|
||||||
|
#define INCLUDED_I18N
|
||||||
|
|
||||||
|
#include <cmake.h>
|
||||||
|
|
||||||
|
// Translators:
|
||||||
|
// Add more, as appropriate.
|
||||||
|
#if PACKAGE_LANGUAGE == LANGUAGE_ENG_USA
|
||||||
|
#include <eng-USA.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CCOLOR_BOLD 500
|
||||||
|
#define CCOLOR_UNDERLINE 501
|
||||||
|
#define CCOLOR_ON 502
|
||||||
|
#define CCOLOR_BRIGHT 503
|
||||||
|
#define CCOLOR_BLACK 504
|
||||||
|
#define CCOLOR_RED 505
|
||||||
|
#define CCOLOR_GREEN 506
|
||||||
|
#define CCOLOR_YELLOW 507
|
||||||
|
#define CCOLOR_BLUE 508
|
||||||
|
#define CCOLOR_MAGENTA 509
|
||||||
|
#define CCOLOR_CYAN 510
|
||||||
|
#define CCOLOR_WHITE 511
|
||||||
|
|
||||||
|
#define CCOLOR_OFF 520
|
||||||
|
#define CCOLOR_UNKNOWN 521
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <i18n.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, const char** argv)
|
int main (int argc, const char** argv)
|
||||||
|
|
105
src/text.cpp
Normal file
105
src/text.cpp
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
static void replace_positional (std::string&, const std::string&, const std::string&);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void split (
|
||||||
|
std::vector<std::string>& results,
|
||||||
|
const std::string& input,
|
||||||
|
const char delimiter)
|
||||||
|
{
|
||||||
|
results.clear ();
|
||||||
|
std::string::size_type start = 0;
|
||||||
|
std::string::size_type i;
|
||||||
|
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||||
|
{
|
||||||
|
results.push_back (input.substr (start, i - start));
|
||||||
|
start = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.length ())
|
||||||
|
results.push_back (input.substr (start));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string trimLeft (const std::string& in, const std::string& t /*= " "*/)
|
||||||
|
{
|
||||||
|
std::string out = in;
|
||||||
|
return out.erase (0, in.find_first_not_of (t));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string trimRight (const std::string& in, const std::string& t /*= " "*/)
|
||||||
|
{
|
||||||
|
std::string out = in;
|
||||||
|
return out.erase (out.find_last_not_of (t) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string trim (const std::string& in, const std::string& t /*= " "*/)
|
||||||
|
{
|
||||||
|
std::string out = in;
|
||||||
|
return trimLeft (trimRight (out, t), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string lowerCase (const std::string& input)
|
||||||
|
{
|
||||||
|
std::string output = input;
|
||||||
|
std::transform (output.begin (), output.end (), output.begin (), tolower);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
static void replace_positional (
|
||||||
|
std::string& fmt,
|
||||||
|
const std::string& from,
|
||||||
|
const std::string& to)
|
||||||
|
{
|
||||||
|
std::string::size_type pos = 0;
|
||||||
|
while ((pos = fmt.find (from, pos)) != std::string::npos)
|
||||||
|
{
|
||||||
|
fmt.replace (pos, from.length (), to);
|
||||||
|
pos += to.length ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
const std::string format (
|
||||||
|
const std::string& fmt,
|
||||||
|
const std::string& arg1)
|
||||||
|
{
|
||||||
|
std::string output = fmt;
|
||||||
|
replace_positional (output, "{1}", arg1);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
41
src/text.h
Normal file
41
src/text.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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_TEXT
|
||||||
|
#define INCLUDED_TEXT
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::string trimLeft (const std::string& in, const std::string& t = " ");
|
||||||
|
std::string trimRight (const std::string& in, const std::string& t = " ");
|
||||||
|
std::string trim (const std::string& in, const std::string& t = " ");
|
||||||
|
void split (std::vector<std::string>&, const std::string&, const char);
|
||||||
|
std::string lowerCase (const std::string&);
|
||||||
|
const std::string format (const std::string&, const std::string&);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
2
test/.gitignore
vendored
2
test/.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
run_all
|
run_all
|
||||||
|
all.log
|
||||||
|
color.t
|
||||||
|
|
|
@ -33,11 +33,10 @@ add_custom_target (build_tests DEPENDS ${test_SRCS}
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
|
||||||
|
|
||||||
foreach (src_FILE ${test_SRCS})
|
foreach (src_FILE ${test_SRCS})
|
||||||
add_executable (${src_FILE} "${src_FILE}.cpp" test.cpp)
|
add_executable (${src_FILE} "${src_FILE}.cpp"
|
||||||
target_link_libraries (${src_FILE} tasksh ${TASKSH_LIBRARIES})
|
../src/Color.cpp
|
||||||
|
../src/text.cpp
|
||||||
|
test.cpp)
|
||||||
|
target_link_libraries (${src_FILE} ${TASKSH_LIBRARIES})
|
||||||
endforeach (src_FILE)
|
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")
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ my $ut = basename ($0);
|
||||||
# Bug <id> - <description>
|
# Bug <id> - <description>
|
||||||
my $output = qx{../src/tasksh --version 2>&1};
|
my $output = qx{../src/tasksh --version 2>&1};
|
||||||
ok ($? == 0, "$ut: version check");
|
ok ($? == 0, "$ut: version check");
|
||||||
like ($output, qr/tasksh version/ms, "$ut: tasksh version found");
|
like ($output, qr/0.9.0.dev/ms, "$ut: tasksh version found");
|
||||||
|
|
||||||
# Cleanup.
|
# Cleanup.
|
||||||
#unlink qw(), $rc;
|
#unlink qw(), $rc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue