From a0148ff81e12b96b1f2dcdda7ebe8719462050f1 Mon Sep 17 00:00:00 2001
From: Andrei Avram <6795248+andreiavrammsd@users.noreply.github.com>
Date: Sat, 7 Sep 2024 08:06:33 +0300
Subject: [PATCH] Devcontainer and coverage (#6)
---
.bazelrc | 8 ++++
.devcontainer/Dockerfile | 59 ++++++++++++++++++++++++++++
.devcontainer/devcontainer.json | 29 ++++++++++++++
.github/workflows/bazel.yml | 12 +++++-
.vscode/extensions.json | 5 +++
.vscode/launch.json | 58 +++++++++++++++++++++++++++
.vscode/settings.json | 1 +
.vscode/tasks.json | 49 +++++++++++++++++++++++
MODULE.bazel.lock | 8 ++--
README.md | 8 +---
codecov.yml | 11 ++++++
jetbrains.svg | 69 ---------------------------------
tests/poly_map_test.cpp | 8 ++--
13 files changed, 241 insertions(+), 84 deletions(-)
create mode 100644 .bazelrc
create mode 100644 .devcontainer/Dockerfile
create mode 100644 .devcontainer/devcontainer.json
create mode 100644 .vscode/extensions.json
create mode 100644 .vscode/launch.json
create mode 100644 .vscode/tasks.json
create mode 100644 codecov.yml
delete mode 100644 jetbrains.svg
diff --git a/.bazelrc b/.bazelrc
new file mode 100644
index 0000000..369e6c0
--- /dev/null
+++ b/.bazelrc
@@ -0,0 +1,8 @@
+build --cxxopt=-std=c++17
+build -c dbg
+build --cxxopt=-Wall
+build --cxxopt=-Wextra
+build --cxxopt=-Wpedantic
+build --cxxopt=-Werror
+
+coverage --experimental_fetch_all_coverage_outputs
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 0000000..63513d8
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,59 @@
+# Use the official Ubuntu base image
+FROM ubuntu:22.04
+
+# Avoid interactive package installation
+ENV DEBIAN_FRONTEND=noninteractive
+
+# Install required packages
+RUN apt-get update && apt-get install -y \
+ build-essential \
+ git \
+ curl \
+ wget \
+ unzip \
+ python3 \
+ python3-pip \
+ gdb \
+ lldb \
+ clang \
+ clang-format \
+ llvm \
+ software-properties-common \
+ && rm -rf /var/lib/apt/lists/*
+
+# Install Bazel
+RUN apt-get update && apt-get install -y apt-transport-https curl gnupg && \
+ curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg && \
+ mv bazel-archive-keyring.gpg /usr/share/keyrings/bazel-archive-keyring.gpg && \
+ echo "deb [signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
+ apt-get update && apt-get install -y bazel && \
+ apt-get clean && \
+ rm -rf /var/lib/apt/lists/*
+
+# Upgrade Bazel
+RUN apt-get update && apt-get full-upgrade -y bazel
+
+# Create a non-root user
+ARG USERNAME=vscode
+ARG USER_UID=1000
+ARG USER_GID=$USER_UID
+
+RUN groupadd --gid $USER_GID $USERNAME \
+ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
+ && apt-get install -y sudo \
+ && echo $USERNAME ALL=\(ALL\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
+ && chmod 0440 /etc/sudoers.d/$USERNAME
+
+RUN wget https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildifier-linux-amd64 \
+ && chmod +x buildifier-linux-amd64 \
+ && sudo mv buildifier-linux-amd64 /usr/local/bin/buildifier
+
+RUN wget https://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.sh \
+ && chmod +x cmake-3.22.6-linux-x86_64.sh \
+ && sudo ./cmake-3.22.6-linux-x86_64.sh --prefix=/usr/local --skip-license
+
+# Set the user to vscode
+USER $USERNAME
+
+# Set the workspace directory
+WORKDIR /workspace
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 0000000..6458b52
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,29 @@
+{
+ "name": "C++ Development with CMake and Bazel",
+ "dockerFile": "Dockerfile",
+ "customizations": {
+ "vscode": {
+ "extensions": [
+ "ms-vscode.cpptools",
+ "ms-vscode.cmake-tools",
+ "ms-vscode.cpptools-extension-pack",
+ "bazelbuild.vscode-bazel",
+ "xaver.clang-format",
+ "twxs.cmake",
+ "fredericbonnet.cmake-test-adapter",
+ "streetsidesoftware.code-spell-checker"
+ ]
+ }
+ },
+ "mounts": [
+ "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
+ "source=${env:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached"
+ ],
+ "workspaceFolder": "/workspace",
+ "runArgs": [
+ "--cap-add=SYS_PTRACE",
+ "--security-opt",
+ "seccomp=unconfined"
+ ],
+ "remoteUser": "vscode"
+}
diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml
index cdd5d39..0070b24 100644
--- a/.github/workflows/bazel.yml
+++ b/.github/workflows/bazel.yml
@@ -16,4 +16,14 @@ jobs:
path: "~/.cache/bazel"
key: bazel
- - run: bazel test poly_map_test --test_output=all
+ - run: bazel coverage poly_map_test --test_output=all
+
+ - name: Coverage
+ run: |
+ sudo apt install -y lcov \
+ && lcov --capture --directory $(bazel info bazel-testlogs)/poly_map_test/ --output-file coverage.info
+
+ - name: Upload coverage reports to Codecov
+ uses: codecov/codecov-action@v4.0.1
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..933c580
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,5 @@
+{
+ "recommendations": [
+ "ms-vscode-remote.remote-containers",
+ ]
+}
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..91fbb6b
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,58 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug CMake Test",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/build/tests/poly_map_test",
+ "args": [],
+ "stopAtEntry": false,
+ "cwd": "${workspaceFolder}",
+ "environment": [],
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "preLaunchTask": "Build with CMake",
+ "miDebuggerPath": "/usr/bin/gdb",
+ "logging": {
+ "trace": true,
+ "engineLogging": true,
+ "traceResponse": true
+ }
+ },
+ {
+ "name": "Debug Bazel Test",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/bazel-bin/poly_map_test",
+ "args": [],
+ "stopAtEntry": false,
+ "cwd": "${workspaceFolder}",
+ "environment": [],
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "preLaunchTask": "Build Bazel Debug",
+ "miDebuggerPath": "/usr/bin/gdb",
+ "logging": {
+ "trace": true,
+ "engineLogging": true,
+ "traceResponse": true
+ },
+ "internalConsoleOptions": "openOnSessionStart"
+ }
+ ]
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0cff5fa..d23d231 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,4 +1,5 @@
{
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
+ "editor.defaultFormatter": "xaver.clang-format",
}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 0000000..49a841a
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,49 @@
+{
+ "version": "2.0.0",
+ "inputs": [
+ {
+ "id": "pickFlakyTest",
+ "type": "command",
+ "command": "bazel.pickTarget",
+ "args": {
+ "query": "kind('.*_test', //...:*)",
+ "placeHolder": "Which test to check for flakyness?"
+ }
+ }
+ ],
+ "tasks": [
+ {
+ "label": "Configure with CMake",
+ "type": "shell",
+ "command": "cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug",
+ "group": "build"
+ },
+ {
+ "label": "Build with CMake",
+ "type": "shell",
+ "command": "cmake --build build",
+ "group": "build",
+ "dependsOn": "Configure with CMake"
+ },
+ {
+ "label": "Check for flakyness",
+ "type": "bazel",
+ "command": "test",
+ "targets": [
+ "${input:pickFlakyTest}"
+ ],
+ "options": [
+ "--runs_per_test=10"
+ ],
+ },
+ {
+ "label": "Build Bazel Debug",
+ "type": "bazel",
+ "command": "build",
+ "targets": [
+ "//:poly_map_test"
+ ],
+ "group": "build"
+ }
+ ]
+}
diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock
index 7a866b8..5482155 100644
--- a/MODULE.bazel.lock
+++ b/MODULE.bazel.lock
@@ -58,8 +58,8 @@
"https://bcr.bazel.build/modules/rules_cc/0.0.9/source.json": "1f1ba6fea244b616de4a554a0f4983c91a9301640c8fe0dd1d410254115c8430",
"https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6",
"https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
- "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe",
- "https://bcr.bazel.build/modules/rules_java/7.6.1/source.json": "8f3f3076554e1558e8e468b2232991c510ecbcbed9e6f8c06ac31c93bcf38362",
+ "https://bcr.bazel.build/modules/rules_java/7.6.5/MODULE.bazel": "481164be5e02e4cab6e77a36927683263be56b7e36fef918b458d7a8a1ebadb1",
+ "https://bcr.bazel.build/modules/rules_java/7.6.5/source.json": "a805b889531d1690e3c72a7a7e47a870d00323186a9904b36af83aa3d053ee8d",
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7",
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/source.json": "a075731e1b46bc8425098512d038d416e966ab19684a10a34f4741295642fc35",
"https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0",
@@ -85,8 +85,8 @@
"https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/source.json": "f1ef7d3f9e0e26d4b23d1c39b5f5de71f584dd7d1b4ef83d9bbba6ec7a6a6459",
"https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0",
"https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27",
- "https://bcr.bazel.build/modules/zlib/1.3/MODULE.bazel": "6a9c02f19a24dcedb05572b2381446e27c272cd383aed11d41d99da9e3167a72",
- "https://bcr.bazel.build/modules/zlib/1.3/source.json": "b6b43d0737af846022636e6e255fd4a96fee0d34f08f3830e6e0bac51465c37c"
+ "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79",
+ "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d"
},
"selectedYankedVersions": {},
"moduleExtensions": {
diff --git a/README.md b/README.md
index 9bba1ba..fb21e2a 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,8 @@
[![bazel](https://github.com/andreiavrammsd/polymap/workflows/bazel/badge.svg)](https://github.com/andreiavrammsd/polymap/actions/workflows/bazel.yml)
+[![codecov](https://codecov.io/github/andreiavrammsd/polymap/graph/badge.svg?token=CKSCACRJXC)](https://codecov.io/github/andreiavrammsd/polymap)
+
### Polymorphic map container.
A recursive map that can have any shape and can hold multiple types for keys and values.
@@ -75,9 +77,3 @@ int main() {
```
See [tests](tests/poly_map_test.cpp).
-
-
-
-Developed with [CLion](https://www.jetbrains.com/?from=serializer)
-
-![JetBrains](jetbrains.svg)
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000..7332f27
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,11 @@
+coverage:
+ precision: 2
+ round: down
+ range: "100...100"
+ status:
+ project: true
+ patch: true
+ changes: true
+
+ignore:
+ - 'tests/*'
diff --git a/jetbrains.svg b/jetbrains.svg
deleted file mode 100644
index 55bbf1a..0000000
--- a/jetbrains.svg
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
diff --git a/tests/poly_map_test.cpp b/tests/poly_map_test.cpp
index c6be267..77353e8 100644
--- a/tests/poly_map_test.cpp
+++ b/tests/poly_map_test.cpp
@@ -1,4 +1,6 @@
-#include
+#include "msd/poly_map.hpp"
+
+#include
#include
#include
@@ -6,8 +8,6 @@
#include
#include
-#include
-
using poly_map_type = msd::poly_map;
class PolyMapTest : public ::testing::Test {
@@ -125,7 +125,7 @@ TEST_F(PolyMapTest, for_each)
EXPECT_EQ((visitor.values[4].get>()), std::make_pair(1, 2));
EXPECT_EQ(visitor.values[5].get(), 199);
- map_visitor visitor_for_const_map {};
+ map_visitor visitor_for_const_map{};
const_map.for_each(visitor_for_const_map);
EXPECT_EQ(visitor_for_const_map.keys.size(), 6);