Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/cpp-kowalski-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: cpp-kowalski-test

on:
push:
branches: [main]
paths: ['cpp/kowalski/**']
pull_request:
branches: ['**']
paths: ['cpp/kowalski/**']

jobs:
cpp-kowalski-test:
runs-on: ubuntu-latest

defaults:
run:
working-directory: cpp/kowalski

steps:
- name: checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
compiler: llvm
vcvarsall: true
clangtidy: true
clangformat: true
cmake: true
ninja: true

- name: configure
run: cmake -S . -B ./build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- name: build
run: cmake --build ./build

- name: test
run: ctest --test-dir ./build --output-on-failure

- name: lint
run: |
find . -name '*.cc' -not -path './build/*' | xargs clang-tidy -p build/

- name: format check
run: |
find . \( -name '*.cc' -o -name '*.h' \) -not -path './build/*' | xargs clang-format --dry-run --Werror
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-tidy
args: [-p=cpp/kowalski/build]
- id: clang-format
args: [-i]
File renamed without changes.
15 changes: 15 additions & 0 deletions cpp/kowalski/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Checks: >
bugprone-*,
clang-analyzer-*,
cppcoreguidelines-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-modernize-use-trailing-return-type,
-readability-magic-numbers,
-cppcoreguidelines-avoid-magic-numbers

WarningsAsErrors: ''
HeaderFilterRegex: '.*'
FormatStyle: file
37 changes: 37 additions & 0 deletions cpp/kowalski/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.23)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(entropylex-kowalski LANGUAGES CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)


include(FetchContent)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()

add_executable(main.test tests/main.test.cc)
target_link_libraries(
main.test
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(main.test)

add_executable(entropylex
main.cc
entropylex8.h
)
11 changes: 11 additions & 0 deletions cpp/kowalski/entropylex8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ENTROPYLEX8_H_
#define ENTROPYLEX8_H_
#include <array>
#include <string>

struct EntropyLex8 {
public:
std::array<std::string, 256> lookup_;
};

#endif // ENTROPYLEX8_H_
7 changes: 7 additions & 0 deletions cpp/kowalski/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "entropylex8.h"
#include <iostream>

int main() {
std::cout << "EntropyLex starting...\n";
return 0;
}
40 changes: 40 additions & 0 deletions cpp/kowalski/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Setup

## Build & Test

```bash
cmake -S . -B ./build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build ./build
ctest --test-dir ./build --output-on-failure
```

## Lint & Format

Requires `compile_commands.json` (generated above).

```bash
# lint
find . -name '*.cc' -not -path './build/*' | xargs clang-tidy -p build/

# format check
find . \( -name '*.cc' -o -name '*.h' \) -not -path './build/*' | xargs clang-format --dry-run --Werror

# format fix
find . \( -name '*.cc' -o -name '*.h' \) -not -path './build/*' | xargs clang-format -i
```

## Pre-commit Hook

```bash
# requires python installed
pip install pre-commit
pre-commit install
```

Runs clang-tidy/clang-format on staged files at commit time. Build `./build` at least once first so `compile_commands.json` exists.

Run against all files manually:
```bash
pre-commit run --all-files
```

14 changes: 14 additions & 0 deletions cpp/kowalski/tests/main.test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef CPP_KOWALSKI_TESTS_MAIN_TEST_CC_
#define CPP_KOWALSKI_TESTS_MAIN_TEST_CC_

#include <gtest/gtest.h>

// Demonstrate some basic assertions.
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.
EXPECT_STRNE("hello", "world");
// Expect equality.
EXPECT_EQ(7 * 6, 42);
}

#endif // CPP_KOWALSKI_TESTS_MAIN_TEST_CC_
Loading