Skip to content

Commit

Permalink
Devcontainer and coverage (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiavrammsd authored Sep 7, 2024
1 parent 6bb9ec2 commit a0148ff
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 84 deletions.
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 11 additions & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
]
}
58 changes: 58 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.defaultFormatter": "xaver.clang-format",
}
49 changes: 49 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
8 changes: 4 additions & 4 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -75,9 +77,3 @@ int main() {
```

See [tests](tests/poly_map_test.cpp).

<br>

Developed with [CLion](https://www.jetbrains.com/?from=serializer)

<a href="https://www.jetbrains.com/?from=serializer">![JetBrains](jetbrains.svg)</a>
11 changes: 11 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage:
precision: 2
round: down
range: "100...100"
status:
project: true
patch: true
changes: true

ignore:
- 'tests/*'
69 changes: 0 additions & 69 deletions jetbrains.svg

This file was deleted.

8 changes: 4 additions & 4 deletions tests/poly_map_test.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <msd/poly_map.hpp>
#include "msd/poly_map.hpp"

#include <gtest/gtest.h>

#include <any>
#include <limits>
#include <string>
#include <tuple>
#include <vector>

#include <gtest/gtest.h>

using poly_map_type = msd::poly_map<int, double, std::string>;

class PolyMapTest : public ::testing::Test {
Expand Down Expand Up @@ -125,7 +125,7 @@ TEST_F(PolyMapTest, for_each)
EXPECT_EQ((visitor.values[4].get<std::pair<int, int>>()), std::make_pair(1, 2));
EXPECT_EQ(visitor.values[5].get<int>(), 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);
Expand Down

0 comments on commit a0148ff

Please sign in to comment.