Skip to content

Commit 145c18f

Browse files
Merge pull request #24 from dreamer-coding/main
Feature strip update
2 parents 7d8468d + 5451174 commit 145c18f

40 files changed

+3927
-6805
lines changed

.github/workflows/meson_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ jobs:
243243
-w /workspace \
244244
${GITHUB_REPOSITORY}:${{ matrix.distro }} \
245245
/bin/bash -c "
246-
meson setup builddir --fatal-meson-warnings -Dwerror=true -Dwith_test=enabled -Dwarning_level=3 -Dc_std=c17
246+
meson setup builddir --fatal-meson-warnings -Dwerror=true -Dwith_test=enabled -Dwarning_level=3
247247
meson compile -C builddir
248248
meson test -C builddir -v"
249249

README.md

Lines changed: 55 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,123 @@
1-
# ***Fossil Test: Unit Testing/Mocking Framework*** - `C, C++`
1+
# ***Fossil Test by Fossil Logic***
22

3-
**Overview:**
4-
Fossil Test is a robust unit testing and mocking framework developed by Fossil Logic. It is designed to facilitate the creation of high-quality test cases across any C and C++ project. The framework supports Behavior-Driven Development (BDD), Domain Driven Development (DDD), and Test-Driven Development (TDD) styles, providing a flexible and comprehensive solution for ensuring software reliability and correctness.
3+
**Fossil Test** is a comprehensive unit testing, mocking, and benchmarking suite created by Fossil Logic, designed to ensure the reliability and performance of C and C++ projects. With support for multiple development methodologies, including Behavior-Driven Development (BDD), Domain-Driven Design (DDD), and Test-Driven Development (TDD), Fossil Test provides a versatile foundation for crafting high-quality test cases across various workflows.
54

6-
In addition to Fossil Test, Fossil Logic also offers two additional frameworks: Fossil Mark and Fossil Mock. Fossil Mark is a powerful benchmarking framework that allows developers to measure the performance of their code and identify areas for optimization. With built-in timing information and detailed reporting, developers can easily track the execution time of each test case and make informed decisions to improve the efficiency of their software.
5+
The Fossil suite consists of three complementary frameworks to streamline the development and testing process:
76

8-
Fossil Mock, on the other hand, provides powerful mocking capabilities that enable developers to simulate the behavior of complex dependencies. This ensures focused and reliable unit tests, as developers can create mock objects that mimic the behavior of real dependencies, allowing for thorough testing of different scenarios.
7+
- **Fossil Test**: The core unit testing framework that enables developers to create, manage, and execute unit tests effectively, ensuring each component functions as expected.
8+
- **Fossil Mock**: A dedicated mocking library that simulates complex dependencies. Using mock objects, developers can isolate and thoroughly test individual components, improving the precision and reliability of test coverage.
9+
- **Fossil Mark**: A benchmarking tool that provides detailed performance insights by measuring execution time, identifying bottlenecks, and offering in-depth reporting to optimize code efficiency.
910

10-
By combining the features of Fossil Test, Fossil Mark, and Fossil Mock, developers can create robust and performant code, ensuring the quality and reliability of their software projects.
11+
Together, **Fossil Test**, **Fossil Mock**, and **Fossil Mark** offer a powerful, integrated toolkit for developing, testing, and optimizing robust software, making them an essential asset for developers committed to quality and performance.
12+
13+
---
1114

1215
**Key Features:**
1316

1417
| Feature | Description |
1518
|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
16-
| **BDD and TDD Support** | Allows developers to write tests in both BDD and TDD styles, catering to various development and testing preferences. |
17-
| **Unit Testing** | Provides a complete suite of tools for writing and executing unit tests, ensuring that individual units of code perform as expected. |
18-
| **Mocking Capabilities** | Includes powerful mocking features that enable developers to simulate the behavior of complex dependencies, ensuring focused and reliable unit tests. |
19-
| **Test Case Management** | Supports organizing and managing test cases efficiently, with features for categorizing, prioritizing, and tagging tests. |
20-
| **Detailed Reporting** | Generates detailed reports on test execution, including information on passed, failed, skipped, and timed-out tests, helping developers quickly address issues. |
21-
| **Performance Tracking** | Tracks the performance of each test case with built-in timing information, allowing developers to monitor and optimize test execution time. |
22-
| **Assertion Detection** | Detects whether assertions are used within the code, ensuring that critical conditions are enforced and identifying areas that may lack proper validation. |
23-
| **Command-Line Interface (CLI)** | Includes a powerful CLI for running tests, generating reports, and managing the test suite from the command line, enhancing automation and integration. |
24-
| **Extensible and Configurable** | Designed to be extensible and configurable, allowing developers to tailor the framework to their specific needs, from reporting formats to tool integration.|
19+
| **BDD, DDD, and TDD Support** | Supports Behavior-Driven, Domain-Driven, and Test-Driven Development styles, catering to various project methodologies. |
20+
| **Comprehensive Unit Testing** | A full suite of tools for creating, managing, and executing unit tests, ensuring that individual units of code behave as expected. |
21+
| **Mocking Capabilities** | Powerful mocking features allow developers to simulate complex dependencies, ensuring focused and reliable unit tests. |
22+
| **Performance Tracking** | Measures and reports the performance of each test case, helping developers optimize test execution time and performance. |
23+
| **Command-Line Interface (CLI)** | A powerful CLI for running tests, generating reports, and managing the test suite, supporting automation and integration workflows. |
24+
25+
---
2526

2627
## ***Prerequisites***
2728

28-
Before getting started, make sure you have the following installed:
29+
To get started with Fossil Test, ensure you have the following installed:
30+
31+
- **Meson Build System**: Fossil Test requires Meson. If you don’t have Meson installed, follow the installation instructions on the official [Meson website](https://mesonbuild.com/Getting-meson.html).
2932

30-
- **Meson Build System**: This project relies on Meson. If you don't have Meson installed, visit the official [Meson website](https://mesonbuild.com/Getting-meson.html) for installation instructions.
33+
---
3134

32-
## Adding Dependency
35+
### Adding Fossil Test Dependency
3336

34-
1. **Install Meson Build System**: Before integrating the dependency, ensure you have Meson `1.3` or newer installed on your host system. You can install it with this command.
37+
To integrate Fossil Test into your project, follow these steps:
3538

39+
1. **Install Meson Build System**:
40+
Install Meson version `1.3` or newer:
3641
```sh
37-
python -m pip install meson # to install Meson
38-
python -m pip install --upgrade meson # to upgrade Meson
42+
python -m pip install meson # To install Meson
43+
python -m pip install --upgrade meson # To upgrade Meson
3944
```
4045

41-
2. **Adding Wrap File**: You can add a `.wrap` file by first navigating to the `subprojects` directory and creating `fossil-test.wrap`. Next, copy the definition into the file:
46+
2. **Create a `.wrap` File**:
47+
Add the `fossil-test.wrap` file in your `subprojects` directory and include the following content:
4248

4349
```ini
4450
# ======================
4551
# Git Wrap package definition
4652
# ======================
4753
[wrap-git]
4854
url = https://github.com/fossillogic/fossil-test.git
49-
revision = v1.0.6
55+
revision = v1.0.7
5056

5157
[provide]
5258
fossil-test = fossil_test_dep
53-
fossil-mock = fossil_mock_dep
54-
fossil-mark = fossil_mark_dep
5559
```
5660

57-
3. **Integrate the New Dependency**: After creating the dependency `.wrap` file, you need to integrate it into your Meson project. This typically involves adding the dependency to your `meson.build` file. Here's an example of how you might do that:
58-
61+
3. **Integrate the Dependency**:
62+
In your `meson.build` file, integrate Fossil Test by adding the following line:
5963
```ini
6064
dep = dependency('fossil-test')
6165
```
6266

63-
This line retrieves the `fossil-test` dependency, allowing you to use it in your project. **Releases Page**: Head over to the [Fossil Test Releases](https://github.com/fossillogic/fossil-test/releases) to find any preferred version of the framework. For the best experience with Fossil Test, it is recommended to always use the latest release.
67+
**Note**: For the best experience, always use the latest release of Fossil Test. Visit the [Fossil Test Releases](https://github.com/fossillogic/fossil-test/releases) page for the latest versions.
68+
69+
---
6470

6571
## Fossil Test CLI Usage
6672

67-
The Fossil Test CLI is a command-line tool designed to help you run and manage your test suite efficiently. Below are the available commands and options:
73+
The Fossil Test CLI provides an efficient way to run and manage tests directly from the terminal. Here are the available commands and options:
6874

6975
### Commands and Options
7076

7177
| Command | Description |
72-
|---------------------------------|-----------------------------------------------------------------------------------------------|
73-
| `--version` | Displays the version of the Fossil Test CLI. |
74-
| `--help` | Shows the help message with usage instructions. |
75-
| `--tip` | Provides a tip or hint about using the Fossil Test CLI. |
76-
| `--info` | Displays information about the test runner. |
77-
| `--author` | Shows information about the author of the test runner. |
78-
| `only=<tag>` or `only=<tags>` | Runs only the tests tagged with the specified tag(s). Tags should be comma-separated for multiple tags. |
79-
| `reverse [enable/disable]` | Enables or disables the reverse order of test execution. |
80-
| `repeat=<number>` | Repeats the test suite for the specified number of times. |
81-
| `shuffle [enable/disable]` | Enables or disables the shuffling of test execution order. |
82-
| `verbose [cutback/normal/verbose]` | Sets the verbosity level of the output. Options are `cutback`, `normal`, and `verbose`. |
83-
| `list` | Lists all available tests. |
84-
| `summary [enable/disable]` | Enables or disables the summary of test results after execution. |
85-
| `color [enable/disable]` | Enables or disables colored output in the terminal. |
86-
| `sanity [enable/disable]` | Enables or disables sanity checks before running the tests. |
87-
88-
### Examples
89-
90-
- Display version information:
91-
92-
```sh
93-
fossil_cli --version
94-
```
78+
|----------------------------------|-----------------------------------------------------------------------------------------------|
79+
| `--version` | Displays the current version of Fossil Test. |
80+
| `--help` | Shows help message with usage instructions. |
81+
| `--info` | Displays detailed information about the test run. |
82+
| `reverse [enable/disable]` | Enables or disables reverse order of test execution. |
83+
| `repeat=<number>` | Repeats the test suite a specified number of times. |
84+
| `shuffle [enable/disable]` | Enables or disables shuffling of test execution order. |
9585

96-
- Show help message:
86+
### Example Usage
9787

88+
- Display the version:
9889
```sh
99-
fossil_cli --help
100-
```
101-
102-
- Run only tests tagged with "unit" and "integration":
103-
104-
```sh
105-
fossil_cli only=unit,integration
90+
fossil_cli --version
10691
```
10792

10893
- Enable reverse order of test execution:
109-
11094
```sh
11195
fossil_cli reverse enable
11296
```
11397

11498
- Repeat the test suite 5 times:
115-
11699
```sh
117100
fossil_cli repeat=5
118101
```
119102

120-
- Enable verbose output:
121-
122-
```sh
123-
fossil_cli verbose verbose
124-
```
125-
126-
- List all available tests:
127-
128-
```sh
129-
fossil_cli list
130-
```
131-
132-
- Enable test result summary:
133-
134-
```sh
135-
fossil_cli summary enable
136-
```
137-
138-
- Enable colored output:
139-
140-
```sh
141-
fossil_cli color enable
142-
```
143-
144-
Feel free to explore and use the various commands and options to tailor the test runner to your needs. For further assistance, refer to the `--help` command.
103+
---
145104

146-
## Configure Options
105+
## Configure Build Options
147106

148-
You have options when configuring the build, each serving a different purpose:
149-
150-
- **Running Tests**: To enable running tests, use `-Dwith_test=enabled` when configuring the build.
151-
152-
Example:
107+
To configure the build system with testing enabled, use the following command:
153108

154109
```sh
155110
meson setup builddir -Dwith_test=enabled
156111
```
157112

113+
---
114+
158115
## ***Contributing and Support***
159116

160-
If you're interested in contributing to this project, encounter any issues, have questions, or would like to provide feedback, don't hesitate to open an issue or visit the [Fossil Logic Docs](https://fossillogic.com/docs) for more information.
117+
If you would like to contribute, have questions, or need help, feel free to open an issue on the [Fossil Test GitHub repository](https://github.com/fossillogic/fossil-test) or consult the [Fossil Logic Docs](https://fossillogic.com/docs).
118+
119+
---
161120

162-
## ***Conclusion:***
121+
## ***Conclusion***
163122

164-
Fossil Test is a comprehensive solution for C and C++ developers aiming to ensure the quality and reliability of their code. By supporting both BDD and TDD, along with powerful mocking, assertion detection, detailed reporting, and a robust CLI, Fossil Test empowers developers to create robust and maintainable test suites. Its flexibility and extensibility make it a valuable tool for projects of any size and complexity, fostering a culture of quality and continuous improvement.
123+
Fossil Test is a powerful and flexible framework for C and C++ developers, designed to support a wide range of testing methodologies such as BDD, DDD, and TDD. With features like mocking, detailed reporting, and performance tracking, Fossil Test empowers developers to create high-quality software and maintainable test suites. Combined with Fossil Mark and Fossil Mock, it provides a complete suite for testing, optimization, and dependency management. Whether you're building small projects or large-scale applications, Fossil Test is an essential tool to ensure the reliability and performance of your code.

code/logic/benchmark/benchmark.c renamed to code/logic/benchmark.c

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,79 @@
1414
* Copyright (C) 2024 Fossil Logic. All rights reserved.
1515
* -----------------------------------------------------------------------------
1616
*/
17-
#include "fossil/benchmark/benchmark.h"
17+
#include "fossil/test/benchmark.h"
1818
#include <stdio.h>
19+
#include <stdlib.h>
20+
#include <string.h>
1921
#include <time.h>
2022
#include <float.h>
2123
#include <stdarg.h>
2224

23-
//
24-
// local types
25-
//
26-
static uint64_t start_time;
27-
2825
#if defined(_WIN32)
29-
static double frequency; // Variable to store the frequency for Windows
26+
#include <windows.h>
27+
static LARGE_INTEGER frequency;
28+
static LARGE_INTEGER start_time;
29+
#elif defined(__APPLE__)
30+
#include <mach/mach_time.h>
31+
clock_t start_time;
32+
#else
33+
#include <sys/time.h>
34+
#include <time.h>
35+
clock_t start_time;
36+
#endif
37+
38+
#ifndef _POSIX_C_SOURCE
39+
#define _POSIX_C_SOURCE 199309L
40+
#endif
41+
42+
#ifndef _GNU_SOURCE
43+
#define _GNU_SOURCE
3044
#endif
3145

3246
void fossil_test_start_benchmark(void) {
3347
#if defined(_WIN32)
34-
LARGE_INTEGER freq;
35-
if (!QueryPerformanceFrequency(&freq)) {
36-
// Handle error
37-
fprintf(stderr, "Error: QueryPerformanceFrequency failed\n");
38-
exit(EXIT_FAILURE);
39-
}
40-
frequency = (double)freq.QuadPart;
41-
if (!QueryPerformanceCounter((LARGE_INTEGER*)&start_time)) {
42-
// Handle error
43-
fprintf(stderr, "Error: QueryPerformanceCounter failed\n");
44-
exit(EXIT_FAILURE);
45-
}
46-
#else
48+
QueryPerformanceFrequency(&frequency);
49+
QueryPerformanceCounter(&start_time);
50+
#elif defined(__APPLE__)
51+
start_time = mach_absolute_time();
52+
#elif defined(_POSIX_VERSION)
4753
struct timespec ts;
48-
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
49-
// Handle error
50-
perror("Error: clock_gettime failed");
51-
exit(EXIT_FAILURE);
52-
}
54+
clock_gettime(CLOCK_MONOTONIC, &ts);
5355
start_time = ts.tv_sec * 1e9 + ts.tv_nsec;
56+
#else
57+
struct timeval tv;
58+
gettimeofday(&tv, NULL);
59+
start_time = (uint64_t)tv.tv_sec * 1e6 + tv.tv_usec;
5460
#endif
5561
}
5662

5763
uint64_t fossil_test_stop_benchmark(void) {
5864
#if defined(_WIN32)
5965
LARGE_INTEGER end_time;
60-
if (!QueryPerformanceCounter(&end_time)) {
61-
// Handle error
62-
fprintf(stderr, "Error: QueryPerformanceCounter failed\n");
63-
exit(EXIT_FAILURE);
64-
}
65-
return (uint64_t)((end_time.QuadPart - start_time) * 1e9 / frequency);
66-
#else
66+
QueryPerformanceCounter(&end_time);
67+
return (uint64_t)((end_time.QuadPart - start_time.QuadPart) * 1e9 / frequency.QuadPart);
68+
#elif defined(__APPLE__)
69+
uint64_t end_time = mach_absolute_time();
70+
mach_timebase_info_data_t timebase;
71+
mach_timebase_info(&timebase);
72+
return (end_time - start_time) * timebase.numer / timebase.denom;
73+
#elif defined(_POSIX_VERSION)
6774
struct timespec ts;
68-
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
69-
// Handle error
70-
perror("Error: clock_gettime failed");
71-
exit(EXIT_FAILURE);
72-
}
73-
return (uint64_t)((ts.tv_sec * 1e9 + ts.tv_nsec) - start_time);
75+
clock_gettime(CLOCK_MONOTONIC, &ts);
76+
return (ts.tv_sec * 1e9 + ts.tv_nsec) - start_time;
77+
#else
78+
struct timeval tv;
79+
gettimeofday(&tv, NULL);
80+
uint64_t end_time = (uint64_t)tv.tv_sec * 1e6 + tv.tv_usec;
81+
return (end_time - start_time) * 1e3;
7482
#endif
7583
}
7684

7785
void assume_duration(double expected, double actual, double unit) {
78-
clock_t end_time = clock();
79-
double elapsed_time = (double)(end_time - start_time) / ((double)CLOCKS_PER_SEC / unit);
80-
if (elapsed_time < expected) {
86+
uint64_t elapsed_time = fossil_test_stop_benchmark();
87+
double elapsed_seconds = elapsed_time / (1e9 / unit); // Convert to the desired time unit
88+
89+
if (elapsed_seconds < expected) {
8190
printf("Benchmark failed: expected %f, got %f\n", expected, actual);
8291
}
8392
}

code/logic/benchmark/meson.build

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)