Skip to content

Commit

Permalink
Merge pull request #2 from edilson258/dev
Browse files Browse the repository at this point in the history
feat: impl vector_remove fn
  • Loading branch information
edilson258 authored Jun 22, 2024
2 parents 9e00568 + ff4f7e2 commit 7452063
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
31 changes: 31 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# C Things Framework

[Learn More](https://github.com/edilson258/cthings)

## Usage from release

This section will guide on how to use cthings from release package.

1. Download you platform release [here](https://github.com/edilson258/cthings/releases/tag/v0.1.0)
2. Unzip to get the `cthings` folder
3. Include the `cthings/include/cthings.h` on your source file

- `main.c`
```C
#include "cthings/include/cthings.h"

int main(void) {
// Your trash code goes here
return 0;
}
```
4. Build your code into <b>object</> file
```shell
clang -c -o main.o main.c
```

5. Link your trash code with my trash code
```shell
clang -o main main.o -lcthings -L./cthings/lib
```
61 changes: 25 additions & 36 deletions src/Testlib.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -32,19 +33,29 @@ struct Test *Test_new(Str_t name, TestBody body) {
void register_test(Str_t name, TestBody body, Str_t filename) {
// @TODO: check bounds of global_test_suite_object

if (global_test_suite_object == NULL) {
if (!global_test_suite_object) {
setup_global_test_suite_object(filename);
}
global_test_suite_object->tests[global_test_suite_object->count++] =
Test_new(name, body);
}

void log_fail(int line_number, Str_t formatter, ...) {
fprintf(stderr, "[\033[31m FAILED \033[0m] %s:%s:%d: ",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number);

va_list args;
va_start(args, formatter);
vfprintf(stderr, formatter, args);
va_end(args);

fprintf(stderr, "\n");
}

Boolean __assert_null__(Any_t expression, int line_number) {
if (expression) {
fprintf(stderr,
"[\033[31m FAILED \033[0m] %s:%s:%d: expects pointer to be NULL\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number);
log_fail(line_number, "expects \"NULL\"");
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand All @@ -53,11 +64,7 @@ Boolean __assert_null__(Any_t expression, int line_number) {

Boolean __assert_true__(Boolean expression, int line_number) {
if (!expression) {
fprintf(stderr,
"[\033[31m FAILED \033[0m] %s:%s:%d: expects \"True\" but found "
"\"False\"\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number);
log_fail(line_number, "expects \"True\"");
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand All @@ -66,11 +73,7 @@ Boolean __assert_true__(Boolean expression, int line_number) {

Boolean __assert_false__(Boolean expression, int line_number) {
if (expression) {
fprintf(stderr,
"[\033[31m FAILED \033[0m] %s:%s:%d: expects \"False\" but found "
"\"True\"\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number);
log_fail(line_number, "expects \"False\"");
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand All @@ -79,12 +82,8 @@ Boolean __assert_false__(Boolean expression, int line_number) {

Boolean __assert_eq_int__(int expected, int provided, int line_number) {
if (expected != provided) {
fprintf(
stderr,
"[\033[31m FAILED \033[0m] %s:%s:%d: expects \"%d\" but found \"%d\"\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number, expected,
provided);
log_fail(line_number, "expects \"%d\" but found \"%d\"", expected,
provided);
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand All @@ -93,12 +92,8 @@ Boolean __assert_eq_int__(int expected, int provided, int line_number) {

Boolean __assert_neq_int__(int expected, int provided, int line_number) {
if (expected == provided) {
fprintf(stderr,
"[\033[31m FAILED \033[0m] %s:%s:%d: expects \"%d\" not equal to "
"\"%d\"\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number, provided,
expected);
log_fail(line_number, "expects \"%d\" and \"%d\" to be different", expected,
provided);
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand All @@ -107,12 +102,8 @@ Boolean __assert_neq_int__(int expected, int provided, int line_number) {

Boolean __assert_eq_str__(Str_t expected, Str_t provided, int line_number) {
if (strcmp(expected, provided) != 0) {
fprintf(
stderr,
"[\033[31m FAILED \033[0m] %s:%s:%d: expects \"%s\" but found \"%s\"\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number, expected,
provided);
log_fail(line_number, "expects \"%s\" but found \"%s\"", expected,
provided);
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand All @@ -121,9 +112,7 @@ Boolean __assert_eq_str__(Str_t expected, Str_t provided, int line_number) {

Boolean __assert_eq_struct__(Any_t expected, Any_t provided, int line_number) {
if (memcmp(expected, provided, sizeof(expected)) != 0) {
fprintf(stderr, "[\033[31m FAILED \033[0m] %s:%s:%d: structs don't match\n",
global_test_suite_object->name,
global_test_suite_object->curr_test->name, line_number);
log_fail(line_number, "provided struct is not equal to expected");
global_test_suite_object->curr_test->has_failed = True;
return False;
}
Expand Down

0 comments on commit 7452063

Please sign in to comment.