Skip to content

Instantly share code, notes, and snippets.

View TheBarbellCoder's full-sized avatar
😎
Happily Coding

Avinash C. Ravi Shankar TheBarbellCoder

😎
Happily Coding
View GitHub Profile
@TheBarbellCoder
TheBarbellCoder / CMakeLists.txt
Created February 3, 2021 16:04
CMake script to compile HelloWorld
cmake_minimum_required(VERSION 3.10.2)
project("GitLab Runner Demo"
DESCRIPTION "Demonstrate GitLab Runner"
LANGUAGES CXX)
add_executable(HelloWorld ${CMAKE_SOURCE_DIR}/hello_world.cpp)
@TheBarbellCoder
TheBarbellCoder / .gitlab-ci.yml
Last active February 11, 2021 13:40
.gitlab-ci.yml to build and run HelloWorld over SSH
ssh_build_and_run:
stage: build
tags:
- ssh
script:
- g++ hello_world.cpp -o HelloWorld
- ./HelloWorld
artifacts:
paths:
- build/HelloWorld
@TheBarbellCoder
TheBarbellCoder / .gitlab-ci.yml
Last active February 11, 2021 13:44
HelloWorld program cross-compiled on an x86 device and tested on a Pi
x86_aarch64_build:
stage: build
tags:
- x86-aarch64
script:
- aarch64-linux-gnu-g++ hello_world.cpp -o HelloWorld
artifacts:
paths:
- HelloWorld
@TheBarbellCoder
TheBarbellCoder / .gitlab-ci.yml
Last active February 18, 2021 05:09
Cross-platform build with docker executor
docker_x86_build:
stage: build
tags:
- x86
- docker
before_script:
- apt-get update && apt-get upgrade -y
- apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
script:
- aarch64-linux-gnu-g++ hello_world.cpp -o HelloWorld
@TheBarbellCoder
TheBarbellCoder / unittest.hpp
Last active November 11, 2022 06:14
Macros to declare and define test cases
// File: unittest.hpp
#define DeclareTest(Module, TestName) \
class Test_##Module##_##TestName: public UnitTest \
{ \
Test_##Module##_##TestName(): UnitTest(){} \
public: \
static Test_##Module##_##TestName* getInstance() \
{ \
static Test_##Module##_##TestName testClass; \
return &testClass; \
@TheBarbellCoder
TheBarbellCoder / testcase.hpp
Last active November 11, 2022 06:14
Test case declaration
// File: testcase.hpp
#include "unittest.hpp"
DeclareTest(dummy, dummycase)
@TheBarbellCoder
TheBarbellCoder / testcase.cpp
Last active November 11, 2022 06:16
Test case definition
// File: testcase.cpp
#include "testcase.hpp"
DefineTest(dummy, dummycase){
// Write your test code here
// ...
}
@TheBarbellCoder
TheBarbellCoder / unittest.hpp
Last active November 11, 2022 06:16
UnitTest class declaration
// File: unittest.hpp
class UnitTest {
protected:
UnitTest() {}
public:
bool isTrue{true};
static std::list<UnitTest*> testList;
virtual ~UnitTest() {}
@TheBarbellCoder
TheBarbellCoder / unittest.cpp
Last active November 11, 2022 06:13
runTests method definition
// File: unitest.cpp
void UnitTest::runTests()
{
// Variables to track passed and failed tests
int passed{0};
int failed{0};
if(testList.empty()) {
std::cout << "No tests registered!!" << std::endl;
return;
@TheBarbellCoder
TheBarbellCoder / unittest.hpp
Last active November 12, 2022 07:12
Macros to register, run, and compare
// File: unittest.hpp
#define RegisterTest(Module, TestName) \
UnitTest::getInstance().testList.push_back( \
Test_##Module##_##TestName::getInstance());
#define RunTests() \
UnitTest::getInstance().runTests();
#define ExpectEQ(arg1, arg2) \
isTrue &= expectEQ(arg1, arg2);