Giter Club home page Giter Club logo

cspec's People

Contributors

asanzo avatar bossiernesto avatar emanuelcasco avatar faloi avatar fedescarpa avatar flbulgarelli avatar jazcarate avatar luchotc avatar maximilianofelice avatar mesaglio avatar mgarciaisaia avatar mortonfox avatar raniagus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cspec's Issues

conflicting types for 'Function' when using with `-lreadline`

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);
      |                       ^~~~~~~~

Permission error for using lib at compiling.

After installing the lib with:

make
sudo make install

when compiling with:

gcc test.c -o test -lcspecs

I was having this permissions issue:
image

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 

image

I don't know if it only happened to me or someone else.

Idea: Syntax change

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?

pending specs

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.

Assertions for arrays

It would be nice to have array equality assertions, comparing element by element.

Some thoughts about this:

  • As seen here, C++ supports literal arrays, but I believe it's mandatory to assign them to a variable: 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 })
  • The user should be able to decide whether the elements must be in the same order or not

Can't include CSpec as an external CMake project

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>
      |          ^~~~~~~~~~~~~~~~

Error Squiggle when copy-pasting example code into Visual Studio Code

Error

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.

Steps to reproduce it

  • Clean install of cspec
  • Copy full example off README.md into a .c file.
  • Check Intellisense's error

Things attempted to fix the error:

  • Copy the replaced text (__describe("Hello world", ({ void __$__()) into the file.
  • Change Intellisense's version of the compiler
  • Switched from GCC to CLang and back
  • Tested in different computers

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.

2023-04-05-19:56:45-screenshot

Publish cspec tests

I've heard that cspecs actually has tests - in cspec ;) - but they are not here nor in the organization repo's. Please publish them!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.