Header-only C++11 library for property-based testing.

Related tags

Testing autocheck
Overview

autocheck

version: Bintray build status: Linux and Mac OSX build status: Windows

Header-only C++11 library for QuickCheck (and later, SmallCheck) testing.

Please consult the wiki for documentation.

Install

conan remote add jfreeman https://api.bintray.com/conan/jfreeman/jfreeman
conan install autocheck/[*]@jfreeman/stable
Comments
  • Add support for MS Visual Studio

    Add support for MS Visual Studio

    Added support for Visual Studio. Added travis-ci build configuration. Added cmake build script for building with GCC, Clang, and Visual Studio Integrated fixes from another fork. Added reporter for catch testing library in addition to gtest.

    opened by JeremyLWright 6
  • discard_if broken

    discard_if broken

    discard_if seems to be broken:

      auto arb = ac::make_arbitrary<string, unsigned int>();
      arb.discard_if(
        [](string key, uint32_t m) {
          printf("key %s m %u\n", key.c_str(), m);
          return key.size() < 1;
        });
    

    I see

    key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 key m 0 Arguments exhausted after 0 tests.

    opened by fugalh 4
  • Adding Visual Studio 2013 support

    Adding Visual Studio 2013 support

    • CMakeLists.txt: Adding cmake to allow simple compilation with visual studio.
    • include/autocheck/generator.hpp: Removed the explicit initializer since visual studio cannot compile variadic templates like this, however it seems this is the default behavior anyway.
    • include/autocheck/value.hpp: Removed the union at the cost of some memory since Visual Studio cannot compile unrestricted unions yet.
    • test/check.cpp: Moved the failing test to a separate test to make the failure more explicit and describe the indent.
    • test/generator_combinators.cpp: Added explicit capture of the factor.
    opened by JeremyLWright 3
  • Doesn't compile in gcc 4.7

    Doesn't compile in gcc 4.7

    Trying to compile the tutorials with gcc (4.7.2) results in errors like

    /home/fugalh/tehcode/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/g++ -std=gnu++11  -I../../include -o build/./insert_sorted.o -c insert_sorted.cpp
    In file included from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/move.h:57:0,
                     from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_pair.h:61,
                     from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/utility:72,
                     from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/algorithm:61,
                     from insert_sorted.cpp:1:
    /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/type_traits: In instantiation of ‘struct std::_Result_of_impl<false, false, prop_insert_sorted_t, const int&, const std::vector<int, std::allocator<int> >&>’:
    /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/type_traits:1857:12:   required from ‘class std::result_of<prop_insert_sorted_t(const int&, const std::vector<int>&)>’
    ../../include/autocheck/apply.hpp:16:3:   required by substitution of ‘template<class F, class ... Args> typename std::result_of<F(const Args& ...)>::type autocheck::apply(F, const std::tuple<_Elements ...>&) [with F = prop_insert_sorted_t; Args = {int, std::vector<int, std::allocator<int> >}]’
    ../../include/autocheck/check.hpp:48:7:   required from ‘void autocheck::check(Property, size_t, Arbitrary, const autocheck::reporter&, autocheck::classifier<Args ...>, bool) [with Args = {int, std::vector<int, std::allocator<int> >}; Property = prop_insert_sorted_t; Arbitrary = autocheck::arbitrary<autocheck::generator<int, void>, autocheck::generator<std::vector<int, std::allocator<int> >, void> >; size_t = long unsigned int]’
    insert_sorted.cpp:40:55:   required from here
    /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/type_traits:1834:9: error: no match for call to ‘(prop_insert_sorted_t) (const int&, const std::vector<int>&)’
    insert_sorted.cpp:17:8: note: candidate is:
    insert_sorted.cpp:19:8: note: template<class T> bool prop_insert_sorted_t::operator()(const T&, std::vector<_RealType>&)
    insert_sorted.cpp:19:8: note:   template argument deduction/substitution failed:
    In file included from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/move.h:57:0,
                     from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_pair.h:61,
                     from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/utility:72,
                     from /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/algorithm:61,
                     from insert_sorted.cpp:1:
    /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/type_traits:1834:9: note:   types ‘std::vector<_RealType>’ and ‘const std::vector<int>’ have incompatible cv-qualifiers
    ‘
    /mnt/gvfs/third-party/2abdfad61e1ced257651899c884f84346417ba37/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../lib/gcc/x86_64-redhat-linux-gnu/4.7.1/../../../../include/c++/4.7.1/type_traits:1834: confused by earlier errors, bailing out
    make: *** [build/./insert_sorted.o] Error 1
    

    When we changed out the const overload in apply.hpp (https://github.com/thejohnfreeman/autocheck/commit/fb2967d807a23522e46aa517b7e271a04cc58fc2) We get the cryptic message:

    $ make
    /home/fugalh/tehcode/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/g++ -std=gnu++11 -I../../include  -I/home/fugalh/local/include  -I../../include -std=c++11 -o build/./insert_sorted.o -c insert_sorted.cpp
    ‘
    ../../include/autocheck/arbitrary.hpp:53: confused by earlier errors, bailing out
    make: *** [build/./insert_sorted.o] Error 1
    
    opened by fugalh 3
  • Small bug fixes

    Small bug fixes

    Hi,

    The first fix just gets rid of an annoying warning that comes if asserts are turned off. If asserts are turned off, the p object in value.hpp is never used.

    The second is in the floating point generator and was causing serious problems. The code was taking the negative of a size_t, which on most platforms is an unsigned int. The negative of an unsigned int is undefined. So, I first convert to a generic floating point value and then negate that.

    Cheers, Ben

    opened by tbenthompson 2
  • vs2013: fix leak, vs2015+: use unrestricted union

    vs2013: fix leak, vs2015+: use unrestricted union

    As unrestricted unions are not used for Visual Studio 2013, default

    T  object;
    

    field is created in value template class default contructor. But as allocation is initialized with None this default object leaks, when we start to generate test values. So, for example, there is a memory leak in the following code, if it is compiled by Visual Studio 2013:

    autocheck::check<std::string>([](const std::string& str) { return true; });
    

    Patch fixes this leakage and turns on unrestricted union usage for Visual Studio 2015+.

    opened by Meteorite 1
  • More msvc bugs

    More msvc bugs

    MSVC chokes on parameter-pack expansion in a couple contexts, so I pretty much just shook the code around until it stopped complaining. As far as I can tell the Gens... related changes have no semantic difference, they just entertain the compiler in slightly different ways.

    The SignedIntegral change here I think is more legit. Previous code was negating an unsigned type (size_t). Probably would have underflowed.

    opened by graydon 1
  • double/ float generator

    double/ float generator

    Doesn't look like it has a generator for double or float yet? Probably just needs something like

    template <typename Double>                                                                                                                                                                                                          
    class generator<                                                                                                                                                                                                                    
    Double,                                                                                                                                                                                                                           
      typename std::enable_if<                                                                                                                                                                                                          
        is_one_of<Double, double, float>::value                                                                                                                                                                                         
      >::type                                                                                                                                                                                                                           
    >                                                                                                                                                                                                                                   
    {                                                                                                                                                                                                                                   
    public:                                                                                                                                                                                                                           
      typedef Double result_type;                                                                                                                                                                                                     
    
      result_type operator() (size_t size) {                                                                                                                                                                                          
        /* Distribution is non-static. */                                                                                                                                                                                             
        std::uniform_real_distribution<Double> dist(0, size);                                                                                                                                                                         
        auto rv = dist(rng());                                                                                                                                                                                                        
        return rv;                                                                                                                                                                                                                    
      }                                                                                                                                                                                                                               
    

    };

    opened by djwatson 1
  • Generators for std::set and std::tuple

    Generators for std::set and std::tuple

    I've extended list_generator so it can be used with more std container, e.g. std::set, and added a default std::tuple generator using cons_generator.

    There's also some fixes for building with C++17

    opened by Adam-Rowell 0
  • Support Request - Generating values within a range

    Support Request - Generating values within a range

    Good Morning John,

    I'm using autocheck, with great success, and I now want to generate values within a range.

    I am testing some date functions and I want to generate years between [1970, 2015] inclusively. I tried the ac::fix() combinator, but that just sets an upper limit on the generated value.

    I see how I can use discard_if() to throw away values that don't match, but that feels so wasteful. Additionally, I want to generate days, months and years so I'd throw away a lot of data before I generated a valid tuple of values.

    How would you recommend generating a range, and if it doesn't exist in autocheck today, what guidance could you provide to how I should add this feature?

    Thank you for your time.

    Sincerely, Jeremy Wright

    opened by JeremyLWright 3
  • shrinking

    shrinking

    Any interest in code for shrinking? I gather you're doing a sort of minimalist SmallCheck-style "expand outwards slowly" approach, but there's still plenty of opportunity for someone to generate non-minimal failures here, I think?

    Edit: I should say, if you are interested, I'd be happy to try sketching such code. Just curious what thoughts you have on the matter. This is a tasteful little library and I'd like to follow your design preferences.

    opened by graydon 4
  • Compilation on G++ 4.6.3

    Compilation on G++ 4.6.3

    Hi,

    apparently it is possible to use the library on older G++, like version 4.6.3 included in Ubuntu 12.04 LTS, by applying a minor fix; I'm pasting it here in case it is useful for anybody.

    @thejohnfreeman Feel free to close this issue as wontfix, because old compilers generally won't support c++11 properly.

    Index: autocheck/include/autocheck/value.hpp
    ===================================================================
    --- autocheck/include/autocheck/value.hpp   (original)
    +++ autocheck/include/autocheck/value.hpp   (new)
    @@ -12,15 +12,15 @@
             None,
             Static,
             Heap
    -      }    allocation = None;
    +      }   allocation /* = None */;
    
           union {
    -        T* pointer = nullptr;
    +        T* pointer /* = nullptr */;
             T  object;
           };
    
         public:
    -      value() {}
    +      value() : allocation(None), pointer(nullptr) {}
    
           value(const value& copy) { *this = copy; }
    

    Although complex code, like generators for classes and enums, seems to break the compiler, the autocheck library is still very useful on pre-c++11 compilers.

    wontfix 
    opened by zoltanp 1
Owner
John Freeman
John Freeman
The C Unit Testing Library on GitHub is a library designed for easy unit testing in C

The C Unit Testing Library on GitHub is a library designed for easy unit testing in C. It was written by Brennan Hurst for the purpose of providing a J-Unit-like testing framework within C for personal projects.

null 1 Oct 11, 2021
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch Windows All dev branch Windows All doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of

Viktor Kirilov 4.5k Jan 4, 2023
A complete unit testing framework in a header

liblittletest A complete unit testing framework in a header liblittletest is an easy to use all-in-an-header testing framework; all you have to do in

Sebastiano Merlino 13 Nov 11, 2021
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch dev branch doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of magnitude) and runtime c

null 4.5k Jan 5, 2023
A micro unit-testing library for C/C++

µ-test A micro unit testing framework for C/C++ to get you up and running with unit-testing ASAP (even without libc). Usage Simply include the C and h

Trevor McKay 1 Dec 8, 2021
C unit tests with a small header-only library.

C unit tests Minimalistic unit tests in C. Uses the __attribute__((constructor)) which, as far as I know, is supported by GCC and clang. So this proba

Ruben van Nieuwpoort 62 Dec 5, 2022
Googletest - Google Testing and Mocking Framework

GoogleTest OSS Builds Status Announcements Release 1.10.x Release 1.10.x is now available. Coming Soon Post 1.10.x googletest will follow Abseil Live

Google 28.8k Jan 9, 2023
Practical mutation testing tool for C and C++

Mull Mull is a tool for Mutation Testing based on LLVM/Clang with a strong focus on C and C++ languages. For installation and usage please refer to th

Mull Project 652 Dec 30, 2022
C++ xUnit-like testing framework without macros

tst C++ testing framework. Installation, documentation, tutorials See WiKi. Features xUnit-like concepts minimal use of preprocessor macros declarativ

cppfw 9 Sep 26, 2022
proftest is a C application for testing the quality of different operating system APIs for profiling.

proftest is a C application for testing the quality of different operating system APIs for profiling.

Felix Geisendörfer 5 Jul 23, 2021
c++ testing framework

iutest iutest - iris unit test framework Welcome to the iutest iutest is framework for writing C++ tests. Features An XUnit test framework. Header onl

srz_zumix 60 Sep 12, 2022
UT: C++20 μ(micro)/Unit Testing Framework

"If you liked it then you "should have put a"_test on it", Beyonce rule UT / μt | Motivation | Quick Start | Overview | Tutorial | Examples | User Gui

boost::ext 956 Jan 3, 2023
A tool to help in testing client/server robustness in the presence of malformed data.

Tool to assist in testing robustness of network-attached services in the presence of malformed data.

Peter Farley 1 Aug 27, 2022
Bayesian A/B testing calculations for C++

BayesTest C++ Bayesian A/B testing calculations for C++ Based on this post by Evan Miller Also available in Rust Installation Include the header in yo

Andrew Kane 2 Nov 14, 2022
5G core testing solution

CoreScope CoreScope combines gNodeB and UE components without any radio transmission. It behaves like a UE and exposes an IP interface, but to the cor

srsRAN 37 Oct 21, 2022
C++ Testing using spies and fakes for isolation and simulation

ELFspy is a library for linux for writing tests using fakes and spies in C++. For very large call graphs, the testing of the higher nodes can be diffi

Robin Nicholson 49 Dec 9, 2022
Modern c++17 unit testing framework on Microsoft Windows, Apple macOS, Linux, iOS and android.

tunit Modern c++17 unit testing framework on Windows, macOS, Linux, iOS and android. Continuous Integration build status Operating system Status Windo

Gammasoft 8 Apr 5, 2022
testing joystick under Linux environment, support monitoring disconnection state and auto recovery mode

qjoystick This qjoystick class is rewritten based on the library: https://github.com/drewnoakes/joystick. Please look at this library if you want to s

ibov 1 Oct 30, 2021
Simple C testing framework

MrTest Simple C testing framework Usage Copy the mrtest.c and mrtest.h file into your project. In order to use the mrtest main: create a .c file that

Maarten Raasveldt 2 Jul 20, 2022