diff --git a/.clang-format b/.clang-format
index 3db5891..b47e6dc 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,25 +1,28 @@
-# Requires clang version >= 3.8
+# Requires clang-format 14 or newer
BasedOnStyle: LLVM
-Standard: Cpp11
-#
+Standard: c++17
+
AccessModifierOffset: -4
-AlignConsecutiveAssignments: true
-AlignEscapedNewlinesLeft: true
-AlignOperands: true
+AlignConsecutiveAssignments:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: false
+AlignConsecutiveDeclarations:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: false
+AlignOperands: Align
AlignTrailingComments: true
-AlignConsecutiveDeclarations: true
AllowShortFunctionsOnASingleLine: Inline
-AlwaysBreakAfterDefinitionReturnType: TopLevel
-AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BreakBeforeBraces: Stroustrup
ColumnLimit: 100
-ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
IndentCaseLabels: false
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
+PackConstructorInitializers: NextLine
PointerAlignment: Left
-SortIncludes: false
+SortIncludes: Never
SpaceAfterCStyleCast: true
# vim: ft=yaml
diff --git a/.cmake-format.yaml b/.cmake-format.yaml
new file mode 100644
index 0000000..8606e38
--- /dev/null
+++ b/.cmake-format.yaml
@@ -0,0 +1,7 @@
+format:
+ line_width: 100
+ tab_size: 4
+ use_tabchars: false
+ max_subgroups_hwrap: 3
+ max_pargs_hwrap: 3
+ dangle_parens: true
diff --git a/.cmakelintrc b/.cmakelintrc
new file mode 100644
index 0000000..187d482
--- /dev/null
+++ b/.cmakelintrc
@@ -0,0 +1 @@
+filter=-linelength,-readability/wonkeycase,-syntax
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index d11a83c..255c5f4 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -11,34 +11,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- - name: Checkout
- uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Check formatting
run: make format-check
test:
- runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ os: [ubuntu-latest, windows-latest, macos-latest]
+ runs-on: ${{ matrix.os }}
steps:
- - name: Checkout
- uses: actions/checkout@v3
-
- - name: Install Ninja, GTest, and GMock
- run: |
- sudo apt-get update
- sudo apt-get install \
- google-mock \
- googletest \
- libgmock-dev \
- libgtest-dev \
- ninja-build
+ - uses: actions/checkout@v4
- name: Build
run: make build
- - name: Run main
- run: make run
-
- name: Test
run: make test
diff --git a/.gitignore b/.gitignore
index 8de37ca..ae1801a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
build
+cmake-build-*
.cache
.ccls-cache
compile_commands.json
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/bootstrap-cpp-kata.iml b/.idea/bootstrap-cpp-kata.iml
new file mode 100644
index 0000000..f08604b
--- /dev/null
+++ b/.idea/bootstrap-cpp-kata.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..9db4553
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
new file mode 100644
index 0000000..e54e87a
--- /dev/null
+++ b/.idea/editor.xml
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..0b76fe5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..cca38d5
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.replit b/.replit
deleted file mode 100644
index 5dec4e6..0000000
--- a/.replit
+++ /dev/null
@@ -1,19 +0,0 @@
-compile = ["make", "build"]
-run = ["make", "test"]
-entrypoint = "main.cpp"
-language = "c++"
-hidden = ["LICENSE", "CMakeLists.txt", "Makefile", ".gitignore", ".clang-format", "compile_commands.json", ".ccls-cache", "build"]
-
-[nix]
-channel = "stable-21_11"
-
-[languages]
-
-[languages.cpp]
-pattern = "**/*.{cpp,h}"
-
-[languages.cpp.languageServer]
-start = "clangd"
-
-[debugger]
-support = false
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..9564b16
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,27 @@
+{
+ "configurations": [
+ {
+ "name": "Mac",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "defines": [],
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "macos-clang-arm64",
+ "configurationProvider": "ms-vscode.cmake-tools"
+ },
+ {
+ "name": "Linux",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "defines": [],
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "linux-gcc-x64",
+ "configurationProvider": "ms-vscode.cmake-tools"
+ }
+ ],
+ "version": 4
+}
\ No newline at end of file
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..91118cb
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,6 @@
+{
+ "recommendations": [
+ "ms-vscode.cpptools",
+ "ms-vscode.cmake-tools",
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..c1421ff
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,28 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug Tests",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/build/test_something",
+ "args": [],
+ "cwd": "${workspaceFolder}",
+ "preLaunchTask": "Build",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "osx": {
+ "MIMode": "lldb",
+ },
+ "linux": {
+ "MIMode": "gdb",
+ "miDebuggerPath": "/usr/bin/gdb",
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..01f1256
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,7 @@
+{
+ "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
+ "cmake.buildDirectory": "${workspaceFolder}/build",
+ "cmake.configureOnOpen": true,
+ "editor.formatOnSave": true,
+ "C_Cpp.formatting": "clangFormat"
+}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 0000000..9ed5ca3
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,33 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "Build",
+ "type": "shell",
+ "command": "make build",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ },
+ {
+ "label": "Run Tests",
+ "type": "shell",
+ "command": "make test",
+ "group": {
+ "kind": "test",
+ "isDefault": true
+ },
+ "dependsOn": "Build"
+ },
+ {
+ "label": "Format",
+ "type": "shell",
+ "command": "make format",
+ "presentation": {
+ "reveal": "silent"
+ },
+ "problemMatcher": []
+ }
+ ]
+}
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3c5cb12..254ccfc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,26 +1,36 @@
cmake_minimum_required(VERSION 3.19)
project(media-player-refactoring-cpp-kata CXX)
-enable_testing()
set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-find_package(GTest REQUIRED)
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
+include(FetchGTest)
+fetch_gtest()
-add_executable(main main.cpp)
+include(GoogleTest)
+
+enable_testing()
file(GLOB tests test_*.cpp)
foreach(test ${tests})
get_filename_component(name ${test} NAME_WE)
add_executable(${name} ${test})
- add_test(${name} ${name})
- target_link_libraries(${name} PRIVATE GTest::gmock GTest::gmock_main)
+ target_link_libraries(${name} PRIVATE GTest::gmock_main)
+
+ gtest_discover_tests(${name})
endforeach()
-add_custom_target(
- copy-compile-commands ALL
- ${CMAKE_COMMAND} -E copy_if_different
- ${CMAKE_BINARY_DIR}/compile_commands.json
- ${CMAKE_CURRENT_LIST_DIR}
-)
+if(UNIX)
+ add_custom_target(
+ copy-compile-commands all
+ ${cmake_command}
+ -e
+ copy_if_different
+ ${cmake_binary_dir}/compile_commands.json
+ ${cmake_current_list_dir}
+ )
+endif()
diff --git a/Makefile b/Makefile
index f268d8c..1bd5a45 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,13 @@
all: build test
-export CXX := clang++
-export GTEST_COLOR := 1
-
BUILDDIR ?= build
SRCS := $(shell git ls-files *.cpp *.h)
.PHONY: build
build:
- cmake -B ${BUILDDIR} -G Ninja .
+ cmake -B ${BUILDDIR} .
cmake --build ${BUILDDIR}
-.PHONY: run
-run:
- cd ${BUILDDIR} && ./main
-
.PHONY: test
test:
ctest --output-on-failure --test-dir ${BUILDDIR}
diff --git a/README.md b/README.md
index 329e0bd..4cf8ba3 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
# Media Player Refactoring C++ Kata
[](https://github.com/Coding-Cuddles/media-player-refactoring-cpp-kata/actions/workflows/main.yml)
-[](https://replit.com/new/github/Coding-Cuddles/media-player-refactoring-cpp-kata)
## Overview
@@ -43,12 +42,12 @@ We have the `MediaFile` class to represent a media file, your task is to:
1. Update the player interfaces to take `MediaFile` objects, e.g.:
- ```cpp
- class IAudioPlayer {
- public:
- virtual void play_audio(const MediaFile& file) = 0;
- };
- ```
+ ```cpp
+ class IAudioPlayer {
+ public:
+ virtual void play_audio(const MediaFile& file) = 0;
+ };
+ ```
2. Create specialized players that can only handle certain formats (i.e.,
`Mp3Player`, `FlacPlayer`, `WavPlayer`).
@@ -112,11 +111,13 @@ classes and interfaces.
You can import this project into [Replit](https://replit.com),
and it will handle all dependencies automatically.
-### Prerequisites
+## Prerequisites
+
+- A compatible C++ compiler that supports at least C++17
+- [CMake](https://cmake.org)
+- [GoogleTest](https://github.com/google/googletest)
-* [CMake 3.19+](https://cmake.org)
-* [Ninja](https://ninja-build.org)
-* [GTest](https://github.com/google/googletest)
+## Usage
### Build
@@ -124,12 +125,6 @@ and it will handle all dependencies automatically.
make build
```
-### Run main
-
-```console
-make run
-```
-
### Run tests
```console
diff --git a/cmake/FetchGTest.cmake b/cmake/FetchGTest.cmake
new file mode 100644
index 0000000..f3778ae
--- /dev/null
+++ b/cmake/FetchGTest.cmake
@@ -0,0 +1,18 @@
+include(FetchContent)
+
+function(fetch_gtest)
+ FetchContent_Declare(
+ googletest
+ URL https://github.com/google/googletest/releases/download/v1.16.0/googletest-1.16.0.tar.gz
+ URL_HASH MD5=9a75eb2ac97300cdb8b65b1a5833f411
+ DOWNLOAD_EXTRACT_TIMESTAMP
+ FALSE
+ FIND_PACKAGE_ARGS
+ NAMES
+ GTest
+ )
+
+ # Prevent overriding parent project's compiler/linker settings on Windows
+ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+ FetchContent_MakeAvailable(googletest)
+endfunction()
diff --git a/main.cpp b/main.cpp
deleted file mode 100644
index 85f8daa..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include
-
-int
-main()
-{
- std::cout << "Hello World!\n";
- return 0;
-}
diff --git a/replit.nix b/replit.nix
deleted file mode 100644
index 5eb161e..0000000
--- a/replit.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{ pkgs }: {
- deps = [
- pkgs.clang_12
- pkgs.cmake
- pkgs.gtest
- pkgs.ninja
- ];
-}