Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ BreakBeforeBraces: Attach
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
ColumnLimit: 120
ColumnLimit: 100
AlignEscapedNewlines: Left
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug tl_app_test",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/build/bin/tl_app_test",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "CMake: Build"
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"ctest",
"Dryrun",
"eabi",
"endforeach",
"libnewlib",
"noninteractive",
"tinyclib",
Expand Down
21 changes: 21 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake: Build",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"${workspaceFolder}/build",
"--config",
"Debug"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"]
}
]
}
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ set_target_properties(tinyclib PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(BUILD_TESTS)
include(CTest)
include(FetchContent)
set(TEST_TARGETS
tl_app_test
tl_config_test
tl_debug_test
tl_error_test
tl_test_test
)

# FetchContent for Unity testing framework
FetchContent_Declare(
Expand All @@ -97,9 +104,9 @@ if(BUILD_TESTS)
target_include_directories(Unity PUBLIC ${unity_SOURCE_DIR}/src)

enable_testing()
foreach(t app config debug error test)
add_executable(tl_${t}_test tests/unit/tl_${t}_test.c)
target_link_libraries(tl_${t}_test unity tinyclib)
add_test(NAME tl_${t}_test COMMAND tl_${t}_test)
foreach(t IN LISTS TEST_TARGETS)
add_executable(${t} tests/unit/${t}.c)
target_link_libraries(${t} unity tinyclib)
add_test(NAME ${t} COMMAND ${t})
endforeach()
endif()
22 changes: 16 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help install build clean test format lint check check-all fix
.DEFAULT_GOAL := help

BUILD_DIR := build
CLANG_FORMAT := $(shell if command -v clang-format >/dev/null 2>&1; then echo clang-format; fi)
Expand All @@ -8,11 +8,16 @@ CLANG_TIDY_EXTRA_ARGS := $(shell if [ "$$(uname)" = "Darwin" ]; then echo "--ext

SRC_FILES := src/*.c include/*.h
TEST_FILES := tests/unit/*.c
ALL_FILES := $(SRC_FILES) $(TEST_FILES)
EXAMPLE_FILES := $(wildcard examples/*/*.c)
ALL_FILES := $(SRC_FILES) $(TEST_FILES) $(EXAMPLE_FILES)

.PHONY: help install build clean clean-bin test format lint check check-all fix

help: ## Show available make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z_-]+:.*## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

configure: ## Configure cmake
cmake --preset default
Expand All @@ -25,6 +30,11 @@ clean: ## Remove build directory
@test -n "$(CURDIR)" && [ "$(CURDIR)" != "/" ]
rm -rf "$(CURDIR)/$(BUILD_DIR)"

clean-bin: ## Remove built binaries from the build directory
@test -n "$(CURDIR)" && [ "$(CURDIR)" != "/" ]
@test -d "$(CURDIR)/$(BUILD_DIR)/bin" || exit 0
find "$(CURDIR)/$(BUILD_DIR)/bin" -mindepth 1 -delete

test: ## Run tests
ctest --preset default

Expand All @@ -40,8 +50,8 @@ lint: ## Check code linting
check: ## Static analysis
@test -n "$(CPPCHECK)" || { echo "error: cppcheck not found"; exit 1; }
$(CPPCHECK) --enable=warning,style,performance,portability --error-exitcode=1 \
--project=$(BUILD_DIR)/compile_commands.json --suppress=missingIncludeSystem \
-i$(BUILD_DIR)
--check-level=exhaustive --project=$(BUILD_DIR)/compile_commands.json \
--suppress=missingIncludeSystem -i$(BUILD_DIR)

check-all: format lint check ## Run all checks

Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ See [mise.toml](mise.toml) for exact versions used.
- [C/C++ for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
- [CMake Tools for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)

## Installation
## Build

```shell
make configure
make build
```

## Usage

## Test

```shell
Expand Down
3 changes: 2 additions & 1 deletion include/tl_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <stdio.h>

/**
* @brief Prints the given message to stderr if the given debug level is greater or equal to the current debug level.
* @brief Prints the given message to stderr if the given debug level is greater or equal to the
* current debug level.
*
* @param level The debug level.
* @param fmt The format string.
Expand Down
45 changes: 21 additions & 24 deletions include/tl_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,27 @@
* @brief Represents an error code.
*/
typedef enum {
TL_ERROR_NONE = 0, // no error

TL_ERROR_INTERNAL = 10, // internal error
TL_ERROR_NOT_FOUND = 11, // not found
TL_ERROR_NOT_READY = 12, // not ready
TL_ERROR_NOT_IMPLEMENTED = 13, // not implemented
TL_ERROR_NOT_SUPPORTED = 14, // not supported
TL_ERROR_NOT_AVAILABLE = 15, // not available

TL_ERROR_TIMEOUT = 20, // timeout error
TL_ERROR_BUSY = 21, // busy
TL_ERROR_IO = 22, // I/O error
TL_ERROR_OUT_OF_RANGE = 23, // out of range error
TL_ERROR_MEMORY_ALLOCATION = 24, // memory allocation error

TL_ERROR_INIT_FAILED = 30, // initialization error
TL_ERROR_NONE = 0, // no error
TL_ERROR_INTERNAL = 10, // internal error
TL_ERROR_NOT_FOUND = 11, // not found
TL_ERROR_NOT_READY = 12, // not ready
TL_ERROR_NOT_IMPLEMENTED = 13, // not implemented
TL_ERROR_NOT_SUPPORTED = 14, // not supported
TL_ERROR_NOT_AVAILABLE = 15, // not available
TL_ERROR_TIMEOUT = 20, // timeout error
TL_ERROR_BUSY = 21, // busy
TL_ERROR_IO = 22, // I/O error
TL_ERROR_OUT_OF_RANGE = 23, // out of range error
TL_ERROR_MEMORY_ALLOCATION = 24, // memory allocation error
TL_ERROR_INIT_FAILED = 30, // initialization error
TL_ERROR_ALREADY_INITIALIZED = 31, // already initialized
TL_ERROR_NOT_INITIALIZED = 32, // not initialized
TL_ERROR_INVALID_ARGUMENT = 33, // invalid argument
TL_ERROR_INVALID_FUNCTION = 34, // invalid function
TL_ERROR_INVALID_INSTANCE = 35, // invalid instance
TL_ERROR_INVALID_SIZE = 36, // invalid size
TL_ERROR_INVALID_TYPE = 37, // invalid type
TL_ERROR_INVALID_VALUE = 38, // invalid value
TL_ERROR_NOT_INITIALIZED = 32, // not initialized
TL_ERROR_INVALID_ARGUMENT = 33, // invalid argument
TL_ERROR_INVALID_FUNCTION = 34, // invalid function
TL_ERROR_INVALID_INSTANCE = 35, // invalid instance
TL_ERROR_INVALID_SIZE = 36, // invalid size
TL_ERROR_INVALID_TYPE = 37, // invalid type
TL_ERROR_INVALID_VALUE = 38, // invalid value
} TLErrorCode;

/**
Expand All @@ -44,7 +41,7 @@ typedef enum {
*/
typedef struct {
TLErrorCode code;
size_t message_size;
size_t message_size;
const char *message;
} TLError;

Expand Down
6 changes: 3 additions & 3 deletions src/tl_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <string.h>

// Init vars
static int arg_count = 0;
static char **args = NULL;
static int arg_count = 0;
static char **args = NULL;

void tl_init_app(int argc, char *argv[]) {
tl_parse_args(argc, argv);
Expand All @@ -19,7 +19,7 @@ void tl_init_app(int argc, char *argv[]) {

void tl_parse_args(int argc, char *argv[]) {
arg_count = argc;
args = argv;
args = argv;
}

bool tl_lookup_flag(const char *flag) {
Expand Down
2 changes: 1 addition & 1 deletion src/tl_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void tl_error_set(TLError *error, TLErrorCode code, const char *message, ...) {
// Clear previous error message
if (error->message) {
free((void *)error->message);
error->message = NULL;
error->message = NULL;
error->message_size = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tl_test_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void tearDown(void) {

static void test_tl_timespec_diff_ns(void) {
struct timespec start = {.tv_sec = 1, .tv_nsec = 500000000};
struct timespec end = {.tv_sec = 2, .tv_nsec = 200000000};
struct timespec end = {.tv_sec = 2, .tv_nsec = 200000000};

long long diff_ns = tl_timespec_diff_ns(&start, &end);

Expand Down