-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CI to the project to verify build under linux, windows and macos
- Loading branch information
Showing
6 changed files
with
276 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: '0 0 1 * *' # This line schedules the workflow to run at 00:00 on the first day of every month | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
include: | ||
- os: ubuntu-latest | ||
compiler: gcc | ||
# - os: ubuntu-latest | ||
# compiler: clang | ||
# - os: windows-latest | ||
# compiler: msvc | ||
# - os: macos-latest | ||
# compiler: clang | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: true | ||
|
||
- name: Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/vcpkg | ||
./build/vcpkg_installed | ||
${{ env.HOME }}/.cache/vcpkg/archives | ||
${{ env.XDG_CACHE_HOME }}/vcpkg/archives | ||
${{ env.LOCALAPPDATA }}\vcpkg\archives | ||
${{ env.APPDATA }}\vcpkg\archives | ||
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}} | ||
restore-keys: | | ||
${{ runner.os }}-${{ env.BUILD_TYPE }}- | ||
- name: Setup Cpp | ||
uses: aminya/setup-cpp@v1 | ||
with: | ||
compiler: ${{ matrix.compiler }} | ||
vcvarsall: ${{ contains(matrix.os, 'windows') }} | ||
cmake: true | ||
ninja: true | ||
vcpkg: true | ||
cppcheck: false | ||
|
||
- name: Prepare the PATH | ||
run: | | ||
if [[ "${{ runner.os }}" == "Windows" ]]; then | ||
echo "$env:USERPROFILE\vcpkg" >> $GITHUB_PATH | ||
echo "$env:USERPROFILE\ninja" >> $GITHUB_PATH | ||
else | ||
echo "$HOME/vcpkg" >> $GITHUB_PATH | ||
echo "$HOME/ninja" >> $GITHUB_PATH | ||
fi | ||
shell: bash | ||
|
||
- name: Install dependencies | ||
run: | | ||
vcpkg install | ||
- name: Build project | ||
shell: bash | ||
run: | | ||
if [ -d build ]; then | ||
echo "Build dir exists" | ||
ls -la build | ||
else | ||
mkdir build | ||
#rm -rf build/* | ||
fi | ||
pushd build | ||
cmake .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
cmake --build . | ||
popd | ||
- name: Run tests | ||
run: | | ||
pushd build | ||
ctest -C Release | ||
popd | ||
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include <regex> | ||
|
||
#include "logfault/logfault.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace std; | ||
using namespace logfault; | ||
|
||
namespace { | ||
struct ClogRedirector { | ||
ClogRedirector(string& out, ostream& ios = std::clog) | ||
: out_{out}, ios_{ios} { | ||
|
||
orig_ = ios.rdbuf(); | ||
ios_.rdbuf(buffer_.rdbuf()); | ||
} | ||
|
||
~ClogRedirector() { | ||
out_ = buffer_.str(); | ||
ios_.rdbuf(orig_); | ||
} | ||
|
||
private: | ||
ostream& ios_; | ||
decltype(std::clog.rdbuf()) orig_{}; | ||
stringstream buffer_; | ||
string& out_; | ||
}; | ||
} // namespace | ||
|
||
TEST(Logfault, HelloTrace) { | ||
|
||
string output; | ||
{ | ||
ClogRedirector redir{output}; | ||
LFLOG_TRACE << "Test log"; | ||
} | ||
|
||
regex pattern{R"(.* TRACE .* Test log.*)"}; | ||
EXPECT_TRUE(regex_search(output, pattern)); | ||
} | ||
|
||
TEST(Logfault, HelloDebug) { | ||
|
||
string output; | ||
{ | ||
ClogRedirector redir{output}; | ||
LFLOG_DEBUG << "Test log"; | ||
} | ||
|
||
regex pattern{R"(.* DEBUGGING .* Test log.*)"}; | ||
EXPECT_TRUE(regex_search(output, pattern)); | ||
} | ||
|
||
TEST(Logfault, HelloInfo) { | ||
|
||
string output; | ||
{ | ||
ClogRedirector redir{output}; | ||
LFLOG_INFO << "Test log"; | ||
} | ||
|
||
regex pattern{R"(.* INFO .* Test log.*)"}; | ||
EXPECT_TRUE(regex_search(output, pattern)); | ||
} | ||
|
||
TEST(Logfault, HelloWarn) { | ||
|
||
string output; | ||
{ | ||
ClogRedirector redir{output}; | ||
LFLOG_WARN << "Test log"; | ||
} | ||
|
||
regex pattern{R"(.* WARNING .* Test log.*)"}; | ||
EXPECT_TRUE(regex_search(output, pattern)); | ||
} | ||
|
||
TEST(Logfault, HelloError) { | ||
|
||
string output; | ||
{ | ||
ClogRedirector redir{output}; | ||
LFLOG_ERROR << "Test log"; | ||
} | ||
|
||
regex pattern{R"(.* ERROR .* Test log.*)"}; | ||
EXPECT_TRUE(regex_search(output, pattern)); | ||
} | ||
|
||
#if defined(__linux__) && defined(LOGFAULT_USE_TID_AS_NAME) | ||
TEST(Logfault, HelloTid) { | ||
|
||
string output; | ||
{ | ||
ClogRedirector redir{output}; | ||
LFLOG_INFO << "Test log"; | ||
} | ||
|
||
regex pattern{R"(.* INFO [0-9]{1,8} Test log.*)"}; | ||
EXPECT_TRUE(regex_search(output, pattern)); | ||
} | ||
#endif | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
||
logfault::LogManager::Instance().AddHandler( | ||
make_unique<logfault::StreamHandler>(clog, logfault::LogLevel::TRACE)); | ||
return RUN_ALL_TESTS(); | ||
} |
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,4 +1,6 @@ | ||
|
||
// General tests for manual testing during development | ||
|
||
#include <iostream> | ||
|
||
#define LOGFAULT_ENABLE_ALL | ||
|