From 96477dfba3937a49aa27bb42a36d8d1636ab8cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0tefka?= Date: Sun, 10 Dec 2023 01:25:53 +0100 Subject: [PATCH] feat(EditorConfig): Add .editorconfig files --- .editorconfig | 13 ++++++ 01/.editorconfig | 14 +++++++ 01/.gitignore | 74 ++++++++++++++++++++++++++++++++++ 01/CMakeLists.txt | 52 ++++++++++++++++++++++++ 01/README.md | 47 ++++++++++++++++++++++ 01/include/CMakeLists.txt | 16 ++++++++ 01/src/CMakeLists.txt | 17 ++++++++ 01/src/main.c | 25 ++++++++++++ 01/tests/CMakeLists.txt | 80 +++++++++++++++++++++++++++++++++++++ 01/tests/src/CMakeLists.txt | 17 ++++++++ 01/tests/src/test.cpp | 31 ++++++++++++++ C_Tempate/.editorconfig | 14 +++++++ 12 files changed, 400 insertions(+) create mode 100644 .editorconfig create mode 100644 01/.editorconfig create mode 100644 01/.gitignore create mode 100644 01/CMakeLists.txt create mode 100644 01/README.md create mode 100644 01/include/CMakeLists.txt create mode 100644 01/src/CMakeLists.txt create mode 100644 01/src/main.c create mode 100644 01/tests/CMakeLists.txt create mode 100644 01/tests/src/CMakeLists.txt create mode 100644 01/tests/src/test.cpp create mode 100644 C_Tempate/.editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..579c6ed --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# EditorConfig is awesome: https://EditorConfig.org +# top-most EditorConfig file +root = true + +# Every file +[*] +# Unix-style newlines with a newline ending every file +end_of_line = lf +# Remove any trailing whitespace characters +trim_trailing_whitespace = true +# Ensure every file ends with a newline +insert_final_newline = true + diff --git a/01/.editorconfig b/01/.editorconfig new file mode 100644 index 0000000..4acf1a3 --- /dev/null +++ b/01/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# Project files +# Matches multiple files with brace expansion notation +[*.{c,h,cc}] + +# Set charset +charset = utf-8 +max_line_length = 80 + +# 2 space indentation +indent_style = space +indent_size = 2 + diff --git a/01/.gitignore b/01/.gitignore new file mode 100644 index 0000000..bd461b5 --- /dev/null +++ b/01/.gitignore @@ -0,0 +1,74 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# Vscode +.vscode/ + +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +.cache/ +CTestTestfile.cmake +_deps +build/ +lib/ +bin/ +*.swp + diff --git a/01/CMakeLists.txt b/01/CMakeLists.txt new file mode 100644 index 0000000..380465c --- /dev/null +++ b/01/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.14) +# Generate compile_commands.json +set(PROJECT_NAME 01) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Turn on testing by default +option(BUILD_TESTING "Build tests" ON) +# Turn off coverage by default +option(ENABLE_COVERAGE "Enable test coverage" ON) + +# Set C standard to C99 +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") + +# Set the project name and version number. This allows for a user of your +project(${PROJECT_NAME} VERSION 0.1) +set(${PROJECT_NAME} 0.1) + +# Function to prepend the subdirectory to source files in subdirectories +FUNCTION(PREPEND var ) + SET(listVar "") + FOREACH(f ${${var}}) + LIST(APPEND listVar "${CMAKE_CURRENT_SOURCE_DIR}/${f}") + ENDFOREACH(f) + SET(${var} "${listVar}" PARENT_SCOPE) +ENDFUNCTION(PREPEND) + +# After a normal build, we can specify the location of various outputs of the +# build. We put executables and static libraries outside the build directory in +# bin/ and lib/, respectively. +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib") + +# Include source code and headers. This calls the CMakeLists.txt in each +# subdirectory. These can define their own libraries, executables, etc. as targets, +# but here we define all exportable targets in the root CMakeLists.txt. +add_subdirectory(src) +add_subdirectory(include) + +# enable unit testing via "make test" once the code has been compiled. +# TODO: Google Test + +if(BUILD_TESTING) + message("Testing enabled") + enable_testing() + add_subdirectory(tests) + target_include_directories(tests PRIVATE include) +endif() + +# Add PROJECT_NAME as an executable target. +add_executable(${PROJECT_NAME} ${SRC} ${INC}) +target_include_directories(${PROJECT_NAME} PRIVATE include) + diff --git a/01/README.md b/01/README.md new file mode 100644 index 0000000..338e33c --- /dev/null +++ b/01/README.md @@ -0,0 +1,47 @@ +# [Day 1](https://adventofcode.com/2023/day/1) + +## Assignment + +### Day 1: Trebuchet?! + +Something is wrong with global snow production, +and you've been selected to take a look. +The Elves have even given you a map; on it, +they've used stars to mark the top fifty locations that are likely to be having problems. + +You've been doing this long enough to know that to restore snow operations, +you need to check all fifty stars by December 25th. + +Collect stars by solving puzzles. +Two puzzles will be made available on each day in the Advent calendar; +the second puzzle is unlocked when you complete the first. +Each puzzle grants one star. Good luck! + +You try to ask why they can't just use a weather machine ("not powerful enough") +and where they're even sending you ("the sky") and why your map looks mostly blank +("you sure ask a lot of questions") and hang on did you just say the sky +("of course, where do you think snow comes from") when you realize +that the Elves are already loading you into a trebuchet +("please hold still, we need to strap you in"). + +As they're making the final adjustments, +they discover that their calibration document (your puzzle input) +has been amended by a very young Elf who was apparently just excited to show off +her art skills. +Consequently, the Elves are having trouble reading the values on the document. + +The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number. + +For example: + +``` +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet +``` + +In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142. + +Consider your entire calibration document. What is the sum of all of the calibration values? + diff --git a/01/include/CMakeLists.txt b/01/include/CMakeLists.txt new file mode 100644 index 0000000..15f3e7a --- /dev/null +++ b/01/include/CMakeLists.txt @@ -0,0 +1,16 @@ + +# Make an explicit list of all source files in IFJ23_INC. This is important +# because CMake is not a build system: it is a build system generator. Suppose +# you add a file foo.cpp to src/ after running cmake .. . If you set +# IFJ23_INC with `file(GLOB ... )`, this is not passed to the makefile; it +# doesn't know that foo.cpp exists and will not re-run cmake. Your +# collaborator's builds will fail and it will be unclear why. Whether you use +# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit +# file list, you know beforehand why your code isn't compiling. +set(INC + ) + +# Form the full path to the source files... +PREPEND(INC) +# ... and pass the variable to the parent scope. +set(INC ${INC} PARENT_SCOPE) diff --git a/01/src/CMakeLists.txt b/01/src/CMakeLists.txt new file mode 100644 index 0000000..b91d51d --- /dev/null +++ b/01/src/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Make an explicit list of all source files in `CMakeDemo_SRC`. This is important +# because CMake is not a build system: it is a build system generator. Suppose +# you add a file foo.cpp to src/ after running cmake .. . If you set +# `CMakeDemo_SRC` with `file(GLOB ... )`, this is not passed to the makefile; +# the makefile doesn't know that foo.cpp exists and will not re-run cmake. Your +# collaborator's builds will fail and it will be unclear why. Whether you use +# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit +# file list, you know beforehand why your code isn't compiling. +set(SRC + main.c + ) + +# Form the full path to the source files... +PREPEND(SRC) +# ... and pass the variable to the parent scope. +set(SRC ${SRC} PARENT_SCOPE) diff --git a/01/src/main.c b/01/src/main.c new file mode 100644 index 0000000..70ba1e7 --- /dev/null +++ b/01/src/main.c @@ -0,0 +1,25 @@ +/** + * Copyright [2023] Jiří Štefka + * Project: AdventOfCode + * @file main.c + * @brief Main entry point + * @author jiriks74 + */ + +#include + +/** + * @brief Main entry point + * @param argc Number of command-line arguments. + * @param argv Array of command-line arguments. + */ +#ifndef TESTING +int main(int argc, char *argv[]) +#endif +#ifdef TESTING + int main_test(int argc, char *argv[]) +#endif +{ + printf("Hello world!\n"); + return 0; +} diff --git a/01/tests/CMakeLists.txt b/01/tests/CMakeLists.txt new file mode 100644 index 0000000..f2a2124 --- /dev/null +++ b/01/tests/CMakeLists.txt @@ -0,0 +1,80 @@ +set(PROJECT_NAME ${PROJECT_NAME} PARENT_SCOPE ) +# GoogleTest requires at least C++14 +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Get GoogleTest +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) + +add_subdirectory(src) +add_executable(tests ${TESTS}) + +# Link test executable against gtest & gtest_main +target_link_libraries( + tests + GTest::gtest_main +) + +target_include_directories(tests PRIVATE + ${CMAKE_SOURCE_DIR}/src + ) + +# Discover tests +include(GoogleTest) +gtest_discover_tests(tests) +add_dependencies(tests ${PROJECT_NAME}) + +# The following section is inspired by https://github.com/cmake-modules/lcov +if(ENABLE_COVERAGE) + message("Test coverage enabled") + # set(exclude_dir "*/tests/* */_deps/* /usr/include/c++/11/**/* /usr/include/c++/**/*") + # set(exclude_dir "*/tests/* */_deps/* /usr/include/c++/11/tuple /usr/include/c++/11/**/*") + + # Check for lcov, gcov and genhtml + find_program(GCOV gcov) + if (NOT GCOV) + message(WARNING "gcov not found") + endif() + find_program(LCOV lcov) + if (NOT LCOV) + message(WARNING "lcov not found") + endif() + find_program(GENHTML genhtml) + if (NOT GENHTML) + message(WARNING "genhtml not found") + endif() + + if (GCOV AND LCOV AND GENHTML) + # Set C compiler flags + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage") + # Set C++ compiler flags + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage") + + set(covname cov.info) + add_custom_target(coverage DEPENDS ${covname}) + add_dependencies(coverage tests ${PROJECT_NAME}) + add_custom_command( + OUTPUT ${covname} + COMMAND ${LCOV} -c -o ${covname} -d ${CMAKE_BINARY_DIR}/tests/CMakeFiles/tests.dir/ -b . --gcov-tool ${GCOV} + COMMAND ${LCOV} -r ${covname} -o ${covname} "*/tests/*" "*/_deps/**/*" "/usr/include/c++/**/*" "/usr/include/c++/11/**/*" + COMMAND ${LCOV} -l ${covname} + COMMAND ${GENHTML} ${covname} -output coverage + COMMAND ${LCOV} -l ${covname} 2>/dev/null | grep Total | sed 's/|//g' | sed 's/Total://g' | awk '{print $1}' | sed s/%//g > coverage/total + ) + set_directory_properties(PROPERTIES + ADDITIONAL_CLEAN_FILES ${covname} + ) + set_directory_properties(PROPERTIES + ADDITIONAL_CLEAN_FILES coverage/ + ) + else() + message(WARNING "Cannot enable coverage. Missing the required tools") + endif() +endif() diff --git a/01/tests/src/CMakeLists.txt b/01/tests/src/CMakeLists.txt new file mode 100644 index 0000000..227c709 --- /dev/null +++ b/01/tests/src/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Make an explicit list of all source files in `IFJ23_TESTS`. This is important +# because CMake is not a build system: it is a build system generator. Suppose +# you add a file foo.cpp to src/ after running cmake .. . If you set +# `IFJ23_TESTS` with `file(GLOB ... )`, this is not passed to the makefile; +# the makefile doesn't know that foo.cpp exists and will not re-run cmake. Your +# collaborator's builds will fail and it will be unclear why. Whether you use +# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit +# file list, you know beforehand why your code isn't compiling. +set(TESTS + test.cpp + ) + +# Form the full path to the source files... +PREPEND(TESTS) +# ... and pass the variable to the parent scope. +set(TESTS ${TESTS} PARENT_SCOPE) diff --git a/01/tests/src/test.cpp b/01/tests/src/test.cpp new file mode 100644 index 0000000..37477b0 --- /dev/null +++ b/01/tests/src/test.cpp @@ -0,0 +1,31 @@ +#include + +#define TESTING + +// Include the source file(s) to be tested. +#include "main.c" + +// Create a test fixture class template - this will be like a "conlection" of +// tests. the : public ::testing::Test part is important! Add it to your fixture +// class. +class HelloTest : public ::testing::Test { + HelloTest() {} + + ~HelloTest() {} + + void SetUp() {} + + void TearDown() {} +}; + +// Add tests to the test fixture class. +// @param fixture_class_name The name of the test fixture class. +// @param test_name The name of the test. +TEST(HelloTest, BasicAssertions) { + // Execute the code to be tested. + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); +} + diff --git a/C_Tempate/.editorconfig b/C_Tempate/.editorconfig new file mode 100644 index 0000000..4acf1a3 --- /dev/null +++ b/C_Tempate/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# Project files +# Matches multiple files with brace expansion notation +[*.{c,h,cc}] + +# Set charset +charset = utf-8 +max_line_length = 80 + +# 2 space indentation +indent_style = space +indent_size = 2 +