From 3975d92651a5a068756f8c93e8af3f841d968d5f Mon Sep 17 00:00:00 2001 From: fanasina Date: Tue, 24 Mar 2026 20:58:42 +0100 Subject: [PATCH] [update] : fix README --- README.md | 136 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 5ce254e..8ed574d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,20 @@ # y_test_h -It is a copy of a project of test like gtest but write in C only. +This is a C-only testing library, similar to gtest but written entirely in C. +To use it, simply copy the y_test_h.h file into your project, include it in your test files, and use the following macros: -But here, it suffice to copy one file "y_test_h.h" and include it in the test file, -and add somme macro functions like `IMPLEMENTATION_FTEST()` to generate all ftest functions -and `IMPLEMENTATION_FMOCK()` to generate all fmock functions. +-`IMPLEMENTATION_FTEST()` to generate all test functions. + +-`IMPLEMENTATION_FMOCK()` to generate all mock functions. # How to create test (ftest) ## Example Example for this file `test.c`: ``` +C +``` +``` #include "y_test_h.h" IMPLEMENTATION_FTEST() @@ -24,23 +28,29 @@ TEST(){ EXPECT_TRUE(true); } ``` -### requirement -I write this program to work on linux, I do not test it on windows or mac! +### Requirements +This program was developed for Linux. It has not been tested on Windows or macOS yet. +``` +Bash +``` ``` $ ls -$ test.c y_test_h.h +test.c y_test_h.h ``` -### compile +### Compilation `gcc -o exectest test.c` -Normaly, it works with `gcc` and `clang` ! +Its typically works with `gcc` and `clang`. -### launch +### Running test `./exectest` -## In function main -### If using options: +## The main function +### Using command-line options: +``` +C +``` ``` int main(int arc, char** argv){ run_all_tests_args(argc, argv); @@ -49,43 +59,52 @@ int main(int arc, char** argv){ ``` We can add execution option like: -`./exectest -h` to print help +`./exectest -h` : Print help -`./exectest -p 5` to parallelize tests, using 5 threads. +`./exectest -p 5` : Parallelize tests using 5 threads. -`./exectest` launch sequential test (1 thread). +`./exectest` : Run tests sequentially (1 thread). -### If using only sequential tests +### Using only sequential tests +``` +C +``` ``` int main(){ run_all_tests(); return 0; } ``` -`./exectest` does not read args! +Note: In this case, `./exectest` does not read command-line arguments. -### If using only parrallel tests +### Using only parrallel tests +``` +C +``` ``` int main(){ run_all_tests_parallel(4); /* to use 4 threads */ return 0; } ``` -`./exectest` does not read args! +Note: In this case, `./exectest` does not read command-line arguments. # FMOCK -We can create and predefined return function regarding the call and condition. - -To simulate response of a function call ! +You can create functions with predefined return values based on specific calls and conditions to simulate the behavior of real functions. ## How to create fmock - +``` +C +``` ``` #include "y_test_h.h" IMPLEMENTATION_FMOCK() ``` -outside all functions: +outside of any function: +``` +C +``` ``` MOCK_FUNC( returnType, @@ -96,24 +115,28 @@ MOCK_FUNC( /* use (returnType) in parathesis if the returType has more than 1 words for example (long int) or (struct someStruct) */ ``` -For example, to create a function mock as signature: +## Example +To mock a function with the signature `int f_mock(int a,int b);` ``` -int f_mock(int a,int b); +C ``` -we use ``` MOCK_FUNC(int, f_mock,(int a,int b),(a,b)) ``` -args: +## Arguments breakdown ``` -returnType: int, -name_function_mock: f_mock, -args prototype with paranthesis: (int a,int b), -args variable names with parathesis (same variable names as prototype): (a,b) +returnType: int, +function_name: f_mock, +Prototype: (int a,int b), +Variables : (a,b) +``` +## Printing variables +You can define a function to print the mock function's variables for logging purposes. The macro uses similar arguments to `MOCK_FUNC`, but the return type is always `char*`. + +Example for `f_mock` : +``` +C ``` -## print variables -We may define a function to print variables of the mock function, it is usefull in logs, the macro has almost the same args as MOCK_FUNC, without returnType wich is always `char*`. -For example with `f_mock` we define: ``` STR_PRINT_CUR_VAR(f_mock, (int a,int b),(a,b)){ char *ret=malloc(150); @@ -121,34 +144,43 @@ STR_PRINT_CUR_VAR(f_mock, (int a,int b),(a,b)){ return ret; } ``` -## define expect call +## Define an expected call +``` +C +``` ``` EXPECT_MOCK_CALL(int, f_mock, (int a,int b), (a