-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
unit tests. ?`cxx/main.cxx`: `%s/testHarnesses/unitTestsCxx/` ?`unitTestsCxx`: Use `expects`, `ensures`, `noexcept`. Process unit test return values, return the bitmask of all unit test return values. [Notice: Before this, `0` was always the return value.] TODO: execute `a.out` in `build.sh` (so that _GitHub_ runners will perform unit tests; if `a.out` returns a non-zero value, the value will show which tests to fix.) [Notice: this will cause _GitHub_ to post that the compilation failed (unless all unit tests pass,) thus have not done so in this commit.] ?`cxx/main.*xx`: +`susuwuUnitTests`: is `extern "C" {` wrap for `Susuwu::unitTestsCxx`, to support more languages. ?`main`: put in `extern "C" {`. ?`build.sh`: Now executes unit tests, with `std::cerr` outputs. Now has (although commented-out) support to pass through unit test return values. ?`README.md`: howto interpret `a.out` return values. ?`SECURITY.md`: `%s/testHarnesses/susuwuUnitTests/`: thus doesn't assume that just C++ projects will use this. Text is now clickable. ?`posts/VirusAnalysis`: include what's new. Is followup to 7dbb0db (+`cxx/Macros.cxx`: Unit tests. ?`cxx/Macros.hxx`:), 388affe (?`cxx/main.cxx`:`testHarnesses` test `classSysGetInput()`, don't reenable input if it was off.), 1ca8d4d (...?cxx/main.cxx:?main /* Store {argc, args} through classSysInit; now other functions can process as {classSysArgc, classSysArgs} */), d3dd3e3 (?cxx/main.cxx:testHarnesses /* Pass funcName to templateMatchAll */) Is progress to issues #3, #14.
- Loading branch information
1 parent
7dbb0db
commit 7a9f52b
Showing
6 changed files
with
136 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,83 @@ | ||
/* Licenses: allows all uses ("Creative Commons"/"Apache 2") */ | ||
#ifndef INCLUDES_cxx_main_cxx | ||
#define INCLUDES_cxx_main_cxx | ||
#include "main.hxx" | ||
#include "AssistantCns.hxx" /* assistantCnsTestsNoexcept */ | ||
#include "ClassSha2.hxx" /* classSha2TestsNoexcept */ | ||
#include "ClassSys.hxx" /* classSysSetConsoleInput classSysTestsNoexcept templateCatchAll */ | ||
#include "Macros.hxx" /* macrosTestsNoexcept SUSUWU_EXPECTS SUSUWU_ENSURES SUSUWU_NOEXCEPT */ | ||
#include "VirusAnalysis.hxx" /* virusAnalysisTestsNoexcept */ | ||
#include <iostream> /* std::cout std::flush std::endl */ | ||
#include <string> /* std::to_string */ | ||
#ifdef SUSUWU_CXX17 /* `type_traits` is C++11 but `is_nothrow_invocable` is C++17 */ | ||
# include <type_traits> /* std::is_nothrow_invocable */ | ||
#endif /* def SUSUWU_CXX17 */ | ||
namespace Susuwu { | ||
const int testHarnesses() { | ||
/* `clang-tidy` off: NOLINTBEGIN(hicpp-signed-bitwise, readability-simplify-boolean-expr) */ | ||
static const SusuwuUnitTestsBitmask unitTestsCxx() SUSUWU_EXPECTS(std::cout.good()) SUSUWU_ENSURES(0 == macrosTestsNoexcept() && true == classSysTestsNoexcept() && true == classSha2TestsNoexcept() && true == virusAnalysisTestsNoexcept() && true == assistantCnsTestsNoexcept()) | ||
#ifdef SUSUWU_CXX17 /* `type_traits` is C++11 but `is_nothrow_invocable` is C++17 */ | ||
SUSUWU_NOEXCEPT(std::is_nothrow_invocable<decltype(std::cout << ""), decltype(std::cout), decltype("")>::value) | ||
#endif /* def SUSUWU_CXX17 */ | ||
{ | ||
int susuwuUnitTestsErrno = 0; | ||
if(!std::cout.good()) { | ||
susuwuUnitTestsErrno |= susuwuUnitTestsConsoleBit; | ||
} | ||
const bool consoleHasInput = classSysGetConsoleInput(); | ||
if(consoleHasInput) { | ||
classSysSetConsoleInput(false); | ||
classSysSetConsoleInput(false); /* disable prompts for unit tests. Moved down to prevent `assert` failures if `cxx/ClassSys.hxx` fails. Notice: this move assumes that the tests above won't block on input */ | ||
} | ||
if(true == classSysGetConsoleInput()) { | ||
susuwuUnitTestsErrno |= susuwuUnitTestsConsoleBit; | ||
} | ||
assert(!classSysGetConsoleInput()); | ||
std::cout << "macrosTestsNoexcept(): " << std::flush /* flush, to show which test starts last if it crashes */; | ||
const int macrosTestsErrno = macrosTestsNoexcept(); | ||
std::cout << (0 == macrosTestsErrno ? "pass" : ("error#" + std::to_string(macrosTestsErrno))) << std::endl; | ||
if(0 == macrosTestsErrno) { | ||
std::cout << "pass" << std::endl; | ||
} else { | ||
std::cout << "error#" << std::to_string(macrosTestsErrno) << std::endl; | ||
susuwuUnitTestsErrno |= susuwuUnitTestsMacrosBit; | ||
} | ||
std::cout << "classSysTestsNoexcept(): " << std::flush; | ||
classSysTestsNoexcept(); | ||
if(true != classSysTestsNoexcept()) { | ||
susuwuUnitTestsErrno |= susuwuUnitTestsClassSysBit; | ||
} | ||
std::cout << "classSha2TestsNoexcept(): " << std::flush; | ||
std::cout << (classSha2TestsNoexcept() ? "pass" : "error") << std::endl; | ||
if(true == classSha2TestsNoexcept()) { | ||
std::cout << "pass" << std::endl; | ||
} else { | ||
std::cout << "error" << std::endl; | ||
susuwuUnitTestsErrno |= susuwuUnitTestsClassSha2Bit; | ||
} | ||
std::cout << "virusAnalysisTestsNoexcept(): " << std::flush; | ||
if(virusAnalysisTestsNoexcept()) { | ||
std::cout << "pass" << std::endl; | ||
} else { | ||
std::cout << "error" << std::endl; | ||
susuwuUnitTestsErrno |= susuwuUnitTestsVirusAnalysisBit; | ||
} | ||
if(consoleHasInput) { | ||
assert(classSysSetConsoleInput(true)); | ||
if(consoleHasInput && false == classSysSetConsoleInput(true)) { | ||
susuwuUnitTestsErrno |= susuwuUnitTestsConsoleBit; | ||
} | ||
std::cout << "assistantCnsTestsNoexcept(): " << std::flush; | ||
if(assistantCnsTestsNoexcept()) { | ||
std::cout << "pass" << std::endl; | ||
} else { | ||
std::cout << "error" << std::endl; | ||
susuwuUnitTestsErrno |= susuwuUnitTestsAssistantCnsBit; | ||
} | ||
return 0; | ||
return susuwuUnitTestsErrno; | ||
} | ||
}; /* namespace Susuwu */ | ||
int main(int argc, const char **args) { | ||
const bool classSysInitSuccess = Susuwu::classSysInit(argc, args); | ||
assert(classSysInitSuccess); | ||
return Susuwu::testHarnesses(); | ||
const SusuwuUnitTestsBitmask susuwuUnitTests() { | ||
return Susuwu::unitTestsCxx(); | ||
} | ||
SusuwuUnitTestsBitmask main(int argc, const char **args) { | ||
if(true != Susuwu::classSysInit(argc, args)) { | ||
return susuwuUnitTestsClassSysBit; | ||
} | ||
return Susuwu::unitTestsCxx(); | ||
} | ||
/* `clang-tidy` on: NOLINTEND(hicpp-signed-bitwise, readability-simplify-boolean-expr) */ | ||
#endif /* ndef INCLUDES_cxx_main_cxx */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Licenses: allows all uses ("Creative Commons"/"Apache 2") */ | ||
#ifndef INCLUDES_cxx_main_hxx | ||
#define INCLUDES_cxx_main_hxx | ||
#ifdef __cplusplus | ||
extern "C" { /* progress to https://github.com/SwuduSusuwu/SubStack/issues/3 , such that other languages can execute unit tests */ | ||
#endif /* def __cplusplus */ | ||
/* `clang-tidy` on: NOLINTBEGIN(hicpp-signed-bitwise) */ | ||
typedef int SusuwuUnitTestsBitmask; /* normal `int`, but used as bitmask (non-zero return value says which tests failed) */ | ||
static const int susuwuUnitTestsMacrosBit = 1 << 0; /* 1: `Macros.hxx`:`macrosTestsNoexcept()` */ | ||
static const int susuwuUnitTestsClassSysBit = 1 << 1; /* 2: `ClassSys.hxx`:`classSysTestsNoexcept()` */ | ||
static const int susuwuUnitTestsClassSha2Bit = 1 << 2; /* 4: `ClassSha2.hxx`:`classSha2TestsNoexcept()` */ | ||
static const int susuwuUnitTestsVirusAnalysisBit = 1 << 3; /* 8: `VirusAnalysis.hxx`:`virusAnalysisTestsNoexcept()` */ | ||
static const int susuwuUnitTestsAssistantCnsBit = 1 << 4; /* 16: `AssistantCns.hxx`:`assistantCnsTestsNoexcept()` */ | ||
static const int susuwuUnitTestsConsoleBit = 1 << 5; /* 32: `classSys.hxx`:`classSysSetConsoleInput()` */ | ||
/* `clang-tidy` on: NOLINTEND(hicpp-signed-bitwise) */ | ||
const SusuwuUnitTestsBitmask susuwuUnitTests(); | ||
SusuwuUnitTestsBitmask main(int argc, const char **args); | ||
#ifdef __cplusplus | ||
} /* extern "C" { */ | ||
#endif /* def __cplusplus */ | ||
#endif /* ndef INCLUDES_cxx_main_hxx */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters