From d22eb0076cc863bcbb7edbdf47ef43e6d434ffc6 Mon Sep 17 00:00:00 2001 From: Agustin Ranieri Date: Thu, 21 Mar 2024 03:55:26 +0000 Subject: [PATCH] Add Code workspace configuration + missing test case (#177) * Add Code workspace configuration * Add test case for string.h * Add integration tests to workspace --- commons.code-workspace | 23 ++++++++++ src/.vscode/c_cpp_properties.json | 18 ++++++++ .../logger/.vscode/c_cpp_properties.json | 18 ++++++++ .../logger/.vscode/launch.json | 32 ++++++++++++++ .../logger/.vscode/tasks.json | 43 +++++++++++++++++++ .../temporal/.vscode/c_cpp_properties.json | 18 ++++++++ .../temporal/.vscode/launch.json | 32 ++++++++++++++ .../temporal/.vscode/tasks.json | 43 +++++++++++++++++++ .../unit-tests/.vscode/c_cpp_properties.json | 19 ++++++++ tests/unit-tests/.vscode/launch.json | 32 ++++++++++++++ tests/unit-tests/.vscode/tasks.json | 43 +++++++++++++++++++ tests/unit-tests/test_string.c | 17 ++++++-- 12 files changed, 335 insertions(+), 3 deletions(-) create mode 100644 commons.code-workspace create mode 100644 src/.vscode/c_cpp_properties.json create mode 100644 tests/integration-tests/logger/.vscode/c_cpp_properties.json create mode 100644 tests/integration-tests/logger/.vscode/launch.json create mode 100644 tests/integration-tests/logger/.vscode/tasks.json create mode 100644 tests/integration-tests/temporal/.vscode/c_cpp_properties.json create mode 100644 tests/integration-tests/temporal/.vscode/launch.json create mode 100644 tests/integration-tests/temporal/.vscode/tasks.json create mode 100644 tests/unit-tests/.vscode/c_cpp_properties.json create mode 100644 tests/unit-tests/.vscode/launch.json create mode 100644 tests/unit-tests/.vscode/tasks.json diff --git a/commons.code-workspace b/commons.code-workspace new file mode 100644 index 00000000..776b2403 --- /dev/null +++ b/commons.code-workspace @@ -0,0 +1,23 @@ +{ + "settings": { + "debug.onTaskErrors": "abort", + "files.associations": { + "*.h": "c", + }, + "C_Cpp.errorSquiggles": "disabled", + }, + "folders": [ + { + "path": "src" + }, + { + "path": "tests/unit-tests" + }, + { + "path": "tests/integration-tests/temporal" + }, + { + "path": "tests/integration-tests/logger" + } + ] +} diff --git a/src/.vscode/c_cpp_properties.json b/src/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..9a87797e --- /dev/null +++ b/src/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference + // for the documentation about the c_cpp_properties.json format + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} diff --git a/tests/integration-tests/logger/.vscode/c_cpp_properties.json b/tests/integration-tests/logger/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..fd3a61ad --- /dev/null +++ b/tests/integration-tests/logger/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference + // for the documentation about the c_cpp_properties.json format + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/../../../src" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} diff --git a/tests/integration-tests/logger/.vscode/launch.json b/tests/integration-tests/logger/.vscode/launch.json new file mode 100644 index 00000000..c5bcaca9 --- /dev/null +++ b/tests/integration-tests/logger/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // See https://go.microsoft.com/fwlink/?linkid=830387 + // for the documentation about the launch.json format + "version": "0.2.0", + "configurations": [ + { + "name": "test", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/commons-integration-test-${workspaceFolderBasename}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "LD_LIBRARY_PATH", + "value": "${workspaceFolder}/../../../src/build" + } + ], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + } + ] +} diff --git a/tests/integration-tests/logger/.vscode/tasks.json b/tests/integration-tests/logger/.vscode/tasks.json new file mode 100644 index 00000000..9d9c0068 --- /dev/null +++ b/tests/integration-tests/logger/.vscode/tasks.json @@ -0,0 +1,43 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "dependsOn": [ + "build_sources", + "build_tests" + ], + }, + { + "label": "build_sources", + "command": "make --no-print-directory -C ../../../src debug", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "build_tests", + "command": "make debug", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "clean", + "command": "make clean", + "type": "shell", + "group": { + "kind": "none" + }, + "problemMatcher": [] + } + ] +} diff --git a/tests/integration-tests/temporal/.vscode/c_cpp_properties.json b/tests/integration-tests/temporal/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..fd3a61ad --- /dev/null +++ b/tests/integration-tests/temporal/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference + // for the documentation about the c_cpp_properties.json format + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/../../../src" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} diff --git a/tests/integration-tests/temporal/.vscode/launch.json b/tests/integration-tests/temporal/.vscode/launch.json new file mode 100644 index 00000000..c5bcaca9 --- /dev/null +++ b/tests/integration-tests/temporal/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // See https://go.microsoft.com/fwlink/?linkid=830387 + // for the documentation about the launch.json format + "version": "0.2.0", + "configurations": [ + { + "name": "test", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/commons-integration-test-${workspaceFolderBasename}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "LD_LIBRARY_PATH", + "value": "${workspaceFolder}/../../../src/build" + } + ], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + } + ] +} diff --git a/tests/integration-tests/temporal/.vscode/tasks.json b/tests/integration-tests/temporal/.vscode/tasks.json new file mode 100644 index 00000000..9d9c0068 --- /dev/null +++ b/tests/integration-tests/temporal/.vscode/tasks.json @@ -0,0 +1,43 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "dependsOn": [ + "build_sources", + "build_tests" + ], + }, + { + "label": "build_sources", + "command": "make --no-print-directory -C ../../../src debug", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "build_tests", + "command": "make debug", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "clean", + "command": "make clean", + "type": "shell", + "group": { + "kind": "none" + }, + "problemMatcher": [] + } + ] +} diff --git a/tests/unit-tests/.vscode/c_cpp_properties.json b/tests/unit-tests/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..1c99343b --- /dev/null +++ b/tests/unit-tests/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference + // for the documentation about the c_cpp_properties.json format + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/../../src", + "${workspaceFolder}/../../cspec" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} diff --git a/tests/unit-tests/.vscode/launch.json b/tests/unit-tests/.vscode/launch.json new file mode 100644 index 00000000..f2215a00 --- /dev/null +++ b/tests/unit-tests/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // See https://go.microsoft.com/fwlink/?linkid=830387 + // for the documentation about the launch.json format + "version": "0.2.0", + "configurations": [ + { + "name": "test", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/commons-unit-test", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "LD_LIBRARY_PATH", + "value": "${workspaceFolder}/../../src/build:${workspaceFolder}/../../cspec/release" + } + ], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + } + ] +} diff --git a/tests/unit-tests/.vscode/tasks.json b/tests/unit-tests/.vscode/tasks.json new file mode 100644 index 00000000..874318a6 --- /dev/null +++ b/tests/unit-tests/.vscode/tasks.json @@ -0,0 +1,43 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "dependsOn": [ + "build_sources", + "build_tests" + ], + }, + { + "label": "build_sources", + "command": "make --no-print-directory -C ../../src debug", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "build_tests", + "command": "make debug", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "clean", + "command": "make clean", + "type": "shell", + "group": { + "kind": "none" + }, + "problemMatcher": [] + } + ] +} diff --git a/tests/unit-tests/test_string.c b/tests/unit-tests/test_string.c index ff5fa76c..ffde1ced 100644 --- a/tests/unit-tests/test_string.c +++ b/tests/unit-tests/test_string.c @@ -193,9 +193,9 @@ context (test_string) { describe("Split") { - it("split_with_separators") { - char *line = "path//to//file"; - char** substrings = string_split(line, "//"); + it("split_with_separator_found") { + char *line = "path\\to\\file"; + char** substrings = string_split(line, "\\"); should_ptr(substrings) not be null; should_string(substrings[0]) be equal to ("path"); @@ -206,6 +206,17 @@ context (test_string) { string_array_destroy(substrings); } end + it("split_with_separator_not_found") { + char *line = "path"; + char **substrings = string_split(line, "/"); + + should_ptr(substrings) not be null; + should_string(substrings[0]) be equal to ("path"); + should_ptr(substrings[1]) be null; + + string_array_destroy(substrings); + } end + it("split_with_empty_string_as_separator") { char *line = "hello"; char** substrings = string_split(line, "");