Skip to content

Commit

Permalink
Add run_tests_in_Docker script
Browse files Browse the repository at this point in the history
  • Loading branch information
mortinger91 committed Aug 7, 2024
1 parent 5a0d01d commit b886ec6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@
"command": "${workspaceFolder}/projectFolder/scripts/windows/run_tests.ps1"
}
},
{
"label": "run_tests_in_Docker",
"type": "shell",
"presentation": {
"focus": true,
"showReuseMessage": false
},
"group": {
"kind": "build"
},

"command": "${workspaceFolder}/projectFolder/scripts/run_tests_in_Docker.sh"
},
// Other tasks
{
"label": "format_code",
Expand Down
10 changes: 2 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Development / Testing image for C++ CMake template project

# base image used as the starting point for this image
FROM debian:12-slim

# ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -36,10 +33,7 @@ COPY projectFolder /projectFolder
# Setting the working directory inside the project folder
WORKDIR /

RUN projectFolder/scripts/build_cmake_debug.sh
RUN projectFolder/scripts/build_debug.sh
RUN projectFolder/scripts/create_release.sh withTests

# The command that is run by default when the container starts
CMD ["./projectFolder/scripts/run_tests.sh"]
# Run this to launch the project binary instead
# CMD ["./projectFolder/build/Debug/bin/cpp-cmake-template"]
CMD ["./projectFolder/scripts/run_tests.sh", "Release"]
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
## Template for a multi-platform C++ CMake project

### Main features:
- CMake files
- CTest unit tests framework
- Github Actions performing build and running the tests
- Github Actions that build and run the tests
- Scripts and VSCode files for ease of use
- Dockerfile for building and running the tests
- Dockerfile for building and running the tests in a container
- Support for compiler cache tools: ccache and sccache
- Formatting via clang-format (that runs automatically in a git pre-commit hook)

Expand All @@ -29,7 +30,7 @@ Execute VSCode task `build_cmake_debug` or run this script:
./projectFolder/scripts/build_cmake_debug.sh

This needs to run the first time and any time you make
changes to a CMake file or add new source files.
changes to a CMake file or add new source or test files.

### How to build the project:
Execute VSCode task `build_debug` or run this script:
Expand All @@ -53,10 +54,10 @@ Execute VSCode task `run_tests` or run this script:

./projectFolder/scripts/run_tests.sh

If you want to run the tests in a fresh Docker container, run these commands:
If you want to build and run the tests in a fresh Docker container
execute VSCode task `run_tests_in_Docker` or run this script:

docker compose down --volumes --rmi all
docker compose up
./projectFolder/scripts/run_tests_in_Docker.sh

### How to add new files to the project:
Add any new source file to a `projectFolder/src/dir` directory.
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
version: "3.7"

services:
dev-container:

build:
context: .
dockerfile: Dockerfile
Expand Down
6 changes: 6 additions & 0 deletions projectFolder/scripts/run_tests_in_Docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -xe

echo "Running tests in a docker container"

docker compose down --volumes --rmi all
docker compose up

0 comments on commit b886ec6

Please sign in to comment.