mumuki / cspec Goto Github PK
View Code? Open in Web Editor NEWSmall BDD framework for C/C++
License: GNU General Public License v3.0
Small BDD framework for C/C++
License: GNU General Public License v3.0
azúcares sintácticos. Please. Just. Don't. My eyes are bleeding.
If I try to compile this code using -lreadline
and -lcspecs
:
#include <readline/readline.h>
#include <cspecs/cspec.h>
It crashes, because both headers have definitions for Function
type:
/usr/include/readline/rltypedefs.h:35:13: error: conflicting types for ‘Function’
35 | typedef int Function () __attribute__ ((deprecated));
| ^~~~~~~~
In file included from src/example.c:3:
/usr/include/cspecs/cspec.h:17:23: note: previous declaration of ‘Function’ was here
17 | typedef void(*Function)(void);
| ^~~~~~~~
After installing the lib with:
make
sudo make install
when compiling with:
gcc test.c -o test -lcspecs
I was having this permissions issue:
The solution was change permissions for cspecs
folder and the lib:
sudo chmod o+r,o+x /usr/include/cspecs/
sudo chmod o+r /usr/include/cspecs/cspec.h
sudo chmod o+r,o+x /usr/lib/libcspecs.so
I don't know if it only happened to me or someone else.
https://github.com/mumuki/cspec/actions/runs/2834934129
Configure git
fatal: --local can only be used inside a git repository
Most C/C++ code formatters (like clang-format
) are not able to understand the {} end
syntax, so they end up formatting CSpec code like this:
#include <cspecs/cspec.h>
#include <stdbool.h>
#include <stdio.h>
context(example) {
describe("Hello world"){
it("true should be true"){should_bool(true) be equal to(true);
}
end
it("true shouldn't be false") {
should_bool(true) not be equal to(false);
}
end
it("this test will fail because 10 is not equal to 11") {
should_int(10) be equal to(11);
}
end
skip("this test will fail because \"Hello\" is not \"Bye\"") {
should_string("Hello") be equal to("Bye");
}
end
}
end
}
In a custom branch I've tried getting rid of end
macro and moving the curly braces inside parenthesis:
#include <cspecs/cspec.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
context(example) {
describe("Hello world", {
char *hello;
before({
hello = strdup("Hello");
});
after({
free(hello);
});
it("true should be true", {
bool the_truth = true;
should_bool(the_truth) be equal to(true);
});
it("true shouldn't be false", {
bool the_truth = true;
should_bool(the_truth) not be equal to(false);
});
it("this test will fail because 10 is not equal to 11", {
int ten = 10;
should_int(ten) be equal to(11);
});
skip("this test will fail because \"Hello\" is not \"Bye\"", {
should_string(hello) be equal to("Bye");
});
});
}
And it indents almost as expected (it doesn't work for single-line blocks, even though I've set every AllowShort*OnASingleLine
option to false/Never/None):
#include <cspecs/cspec.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
context(example) {
describe("Hello world", {
char *hello;
before({ hello = strdup("Hello"); });
after({ free(hello); });
it("true should be true", {
bool the_truth = true;
should_bool(the_truth) be equal to(true);
});
it("true shouldn't be false", {
bool the_truth = true;
should_bool(the_truth) not be equal to(false);
});
it("this test will fail because 10 is not equal to 11", {
int ten = 10;
should_int(ten) be equal to(11);
});
skip("this test will fail because \"Hello\" is not \"Bye\"", { should_string(hello) be equal to("Bye"); });
});
}
But, I find this syntax much more easier to understand and use, and also more beginner friendly. What do you think?
If someone forks the repository and pushes new updates to master branch, GitHub workflows are being executed: https://github.com/RaniAgus/cspec/pkgs/container/cspec-alpine
They should be skipped.
Implement pending
feature to informe that a spec or suite of specs aren't currently passing, but shouldn't make the test fail.
It would be great if it could replace both describe
and it
, as in rspec
.
It would be nice to have array equality assertions, comparing element by element.
Some thoughts about this:
int expected[] = { 16, 2, 77, 40, 12071 };
. It would be great to avoid the variable and write something like should(numbers) be equal({ 16, 2, 77, 40, 12071 })
CMake allows to include an external project with Git adding these lines:
set(EXTERNAL_PROJECT_DIR ${CMAKE_BINARY_DIR}/external)
include(ExternalProject)
ExternalProject_Add(cspecs
GIT_REPOSITORY https://github.com/mumuki/cspec
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECT_DIR}
)
include_directories(${EXTERNAL_PROJECT_DIR}/include)
link_directories(${EXTERNAL_PROJECT_DIR}/lib)
link_libraries(cspecs)
But it fails because the installation doesn't include CSpec's header:
[ 6%] Creating directories for 'cspecs'
[ 12%] Performing download step (git clone) for 'cspecs'
-- Avoiding repeated git clone, stamp file is up to date: '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-stamp/cspecs-gitclone-lastrun.txt'
[ 18%] Performing update step for 'cspecs'
HEAD is now at 80569c0 Merge pull request #29 from mumuki/shrink-image
[ 25%] No patch step for 'cspecs'
[ 31%] Performing configure step for 'cspecs'
-- Configuring done
-- Generating done
-- Build files have been written to: /home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build
[ 37%] Performing build step for 'cspecs'
make[5]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
make[6]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
make[7]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
Consolidate compiler generated dependencies of target cspecs
make[7]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
[100%] Built target cspecs
make[6]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
make[5]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
[ 43%] Performing install step for 'cspecs'
make[5]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
make[6]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
make[7]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
make[7]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
[100%] Built target cspecs
make[6]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
Install the project...
-- Install configuration: ""
-- Up-to-date: /home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/external/lib/libcspecs.so
make[5]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build/cspecs-prefix/src/cspecs-build'
[ 50%] Completed 'cspecs'
make[4]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build'
[ 50%] Built target cspecs
make[4]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build'
make[4]: Leaving directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build'
make[4]: Entering directory '/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/build'
[ 56%] Building C object CMakeFiles/commons-unit-test.dir/test_bitarray.c.o
/home/aranieri/so-commons-library-install-from-zip/tests/unit-tests/test_bitarray.c:20:10: fatal error: cspecs/cspec.h: No such file or directory
20 | #include <cspecs/cspec.h>
| ^~~~~~~~~~~~~~~~
Upon clean install of cspec, following the explanation in the README.md file, and including the required header files for the example file copied from the previous file, Visual Studio Code (with C/C++ extensions installed) detects the error:
argument of type "void" is incompatible with parameter of type "Runnable"C/C++(167)
Though this error is only aesthetic, as the file compiles correctly and the tests run as expected.
__describe("Hello world", ({ void __$__()
) into the file.Attached a screenshot of the error in question, the second error comes from not detecting the first one as a correct structure, so it doesn't matter for the initial issue.
I've heard that cspecs actually has tests - in cspec ;) - but they are not here nor in the organization repo's. Please publish them!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.