commit
d2714daaa2
13 changed files with 224 additions and 0 deletions
@ -0,0 +1,41 @@
|
||||
# -*- yaml -*- |
||||
|
||||
--- |
||||
BasedOnStyle: WebKit |
||||
IndentWidth: 4 |
||||
--- |
||||
Language: Cpp |
||||
|
||||
AlignAfterOpenBracket: Align |
||||
AlignEscapedNewlines: Left |
||||
AlignOperands: Align |
||||
AlignTrailingComments: true |
||||
|
||||
AllowAllArgumentsOnNextLine: false |
||||
AllowAllConstructorInitializersOnNextLine: true |
||||
AllowAllParametersOfDeclarationOnNextLine: false |
||||
AllowShortCaseLabelsOnASingleLine: true |
||||
AllowShortLambdasOnASingleLine: All |
||||
|
||||
AlwaysBreakTemplateDeclarations: Yes |
||||
IndentPPDirectives: BeforeHash |
||||
RequiresClausePosition: SingleLine |
||||
|
||||
BraceWrapping: |
||||
AfterEnum: false |
||||
AfterFunction: true |
||||
BeforeCatch: true |
||||
BeforeElse: true |
||||
BeforeLambdaBody: false |
||||
SplitEmptyRecord: false |
||||
BreakBeforeBraces: Custom |
||||
BreakInheritanceList: BeforeComma |
||||
|
||||
SpaceAfterTemplateKeyword: false |
||||
SpaceInEmptyBlock: false |
||||
NamespaceIndentation: None |
||||
FixNamespaceComments: true |
||||
Standard: c++20 |
||||
TabWidth: 4 |
||||
UseTab: AlignWithSpaces |
||||
... |
@ -0,0 +1,7 @@
|
||||
# Directories |
||||
|
||||
.cache/ |
||||
.clangd/ |
||||
build/ |
||||
|
||||
# Files |
@ -0,0 +1,3 @@
|
||||
[submodule "vendor/munit"] |
||||
path = vendor/munit |
||||
url = https://github.com/nemequ/munit |
@ -0,0 +1,62 @@
|
||||
set(PROJECT "bootdev") |
||||
|
||||
cmake_minimum_required(VERSION 3.16) |
||||
project(${PROJECT} C) |
||||
|
||||
set(CMAKE_C_STANDARD 11) |
||||
set(CMAKE_C_STANDARD_REQUIRED ON) |
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -g -pg") |
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
||||
|
||||
# ------------------------------------------ |
||||
# Library µnit |
||||
|
||||
file(GLOB_RECURSE LIBRARY_SOURCES "vendor/munit/*.c") |
||||
|
||||
add_library(munit ${LIBRARY_SOURCES}) |
||||
|
||||
target_include_directories(munit PUBLIC |
||||
"vendor/munit") |
||||
|
||||
# ------------------------------------------ |
||||
# Executable |
||||
|
||||
file(GLOB LESSONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src/*) |
||||
|
||||
set(ALL_RUN "") |
||||
set(ALL_TARGETS "") |
||||
foreach(LESSON ${LESSONS}) |
||||
if(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${LESSON}) |
||||
continue() |
||||
endif() |
||||
|
||||
file(GLOB LESSON_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${LESSON}/*.c) |
||||
if(NOT LESSON_SOURCES) |
||||
continue() |
||||
endif() |
||||
|
||||
# Get last directory name of the path to use as exe |
||||
get_filename_component(EXE_NAME ${LESSON} NAME) |
||||
|
||||
add_executable(${EXE_NAME} ${LESSON_SOURCES}) |
||||
target_include_directories(${EXE_NAME} PRIVATE |
||||
${CMAKE_CURRENT_SOURCE_DIR}/${LESSON} |
||||
"vendor/munit") |
||||
target_link_libraries(${EXE_NAME} munit) |
||||
|
||||
# Collect all the directory names for the run target |
||||
list(APPEND ALL_RUN COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}) |
||||
list(APPEND ALL_TARGETS ${EXE_NAME}) |
||||
endforeach() |
||||
|
||||
# ------------------------------------------ |
||||
# Execute target |
||||
|
||||
add_custom_target(run |
||||
${ALL_RUN}) |
||||
|
||||
foreach(target ${ALL_TARGETS}) |
||||
add_dependencies(run ${target}) |
||||
endforeach() |
@ -0,0 +1,5 @@
|
||||
typedef enum Color { |
||||
RED, |
||||
GREEN, |
||||
BLUE, |
||||
} color_t; |
@ -0,0 +1,27 @@
|
||||
#include "munit.h" |
||||
|
||||
#include "color.h" |
||||
|
||||
munit_case(RUN, test_color_enum1, { |
||||
assert_int(RED, ==, 0, "RED is defined as 0"); |
||||
assert_int(GREEN, ==, 1, "GREEN is defined as 1"); |
||||
assert_int(BLUE, ==, 2, "BLUE is defined as 2"); |
||||
}); |
||||
|
||||
munit_case(SUBMIT, test_color_enum2, { |
||||
assert_int(RED, !=, 4, "RED is not defined as 4"); |
||||
assert_int(GREEN, !=, 2, "GREEN is not defined as 2"); |
||||
assert_int(BLUE, !=, 0, "BLUE is not defined as 0"); |
||||
}); |
||||
|
||||
int main() { |
||||
MunitTest tests[] = { |
||||
munit_test("/are_defined", test_color_enum1), |
||||
munit_test("/are_defined_correctly", test_color_enum2), |
||||
munit_null_test, |
||||
}; |
||||
|
||||
MunitSuite suite = munit_suite("colors", tests); |
||||
|
||||
return munit_suite_main(&suite, NULL, 0, NULL); |
||||
} |
@ -0,0 +1,5 @@
|
||||
typedef enum Color { |
||||
RED = 55, |
||||
GREEN = 176, |
||||
BLUE = 38, |
||||
} color_t; |
@ -0,0 +1,27 @@
|
||||
#include "munit.h" |
||||
|
||||
#include "color.h" |
||||
|
||||
munit_case(RUN, test_colors_defined, { |
||||
assert_int(RED, ==, 55, "RED is defined as 55 (nvim green!)"); |
||||
assert_int(GREEN, ==, 176, "GREEN is defined as 176 (nvim green!)"); |
||||
assert_int(BLUE, ==, 38, "BLUE is defined as 38 (nvim green!)"); |
||||
}); |
||||
|
||||
munit_case(SUBMIT, test_colors_defined_correctly, { |
||||
assert_int(RED, !=, 0, "RED is not defined as 0 (vsc*de blue!)"); |
||||
assert_int(GREEN, !=, 120, "GREEN is not defined as 120 (vsc*de blue!)"); |
||||
assert_int(BLUE, !=, 215, "BLUE is not defined as 215 (vsc*de blue!)"); |
||||
}); |
||||
|
||||
int main() { |
||||
MunitTest tests[] = { |
||||
munit_test("/defined", test_colors_defined), |
||||
munit_test("/defined_vscode", test_colors_defined_correctly), |
||||
munit_null_test, |
||||
}; |
||||
|
||||
MunitSuite suite = munit_suite("colors", tests); |
||||
|
||||
return munit_suite_main(&suite, NULL, 0, NULL); |
||||
} |
@ -0,0 +1,7 @@
|
||||
#include "http.h" |
||||
|
||||
char* http_to_str(http_error_code_t code) |
||||
{ |
||||
// ?
|
||||
return 0; |
||||
} |
@ -0,0 +1,11 @@
|
||||
#pragma once |
||||
|
||||
typedef enum { |
||||
HTTP_BAD_REQUEST = 400, |
||||
HTTP_UNAUTHORIZED = 401, |
||||
HTTP_NOT_FOUND = 404, |
||||
HTTP_TEAPOT = 418, |
||||
HTTP_INTERNAL_SERVER_ERROR = 500 |
||||
} http_error_code_t; |
||||
|
||||
char* http_to_str(http_error_code_t code); |
@ -0,0 +1,27 @@
|
||||
#include "munit.h" |
||||
|
||||
#include "http.h" |
||||
|
||||
munit_case(RUN, test_switch_enum, { |
||||
assert_string_equal(http_to_str(HTTP_BAD_REQUEST), "400 Bad Request", ""); |
||||
assert_string_equal(http_to_str(HTTP_UNAUTHORIZED), "401 Unauthorized", ""); |
||||
assert_string_equal(http_to_str(HTTP_NOT_FOUND), "404 Not Found", ""); |
||||
assert_string_equal(http_to_str(HTTP_TEAPOT), "418 I AM A TEAPOT!", ""); |
||||
assert_string_equal(http_to_str(HTTP_INTERNAL_SERVER_ERROR), "500 Internal Server Error", ""); |
||||
}); |
||||
|
||||
munit_case(SUBMIT, test_switch_enum_default, { |
||||
assert_string_equal(http_to_str((http_error_code_t)999), "Unknown HTTP status code", ""); |
||||
}); |
||||
|
||||
int main() { |
||||
MunitTest tests[] = { |
||||
munit_test("/switch_enum", test_switch_enum), |
||||
munit_test("/switch_enum_default", test_switch_enum_default), |
||||
munit_null_test, |
||||
}; |
||||
|
||||
MunitSuite suite = munit_suite("http", tests); |
||||
|
||||
return munit_suite_main(&suite, NULL, 0, NULL); |
||||
} |
Loading…
Reference in new issue