npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

trompeloeil.cxx

v49.0.0

Published

Header only C++14 mocking framework; Björn Fahller (2014).

Readme

Trompeloeil

trompeloeil logo

CI codecov

Get: Conan

trompe l'oeil noun (Concise Encyclopedia) Style of representation in which a painted object is intended to deceive the viewer into believing it is the object itself...

What is it?

A thread-safe header-only mocking framework for C++11/14 using the Boost Software License 1.0, by Björn Fahller.

Installation

Run:

$ npm i trompeloeil.cxx

And then include trompeloeil.hpp as follows:

#include "node_modules/trompeloeil.cxx/include/trompeloeil.hpp"

Documentation

Also, follow up with the post on sequencing for examples on how to restrict or relax allowed sequences of matching calls.

Teaser

#include <trompeloeil.hpp>

class Interface
{
public:
  virtual ~Interface() = default;
  virtual bool foo(int, std::string& s) = 0;
  virtual bool bar(int) = 0;
  virtual bool bar(std::string) = 0;
};

void interface_func(Interface*); // function to test

class Mock : public Interface
{
public:
  MAKE_MOCK(foo, auto (int, std::string&) -> bool, override);
  MAKE_MOCK(bar, auto (int) -> bool, override);
  MAKE_MOCK(bar, auto (std::string) -> bool, override);
  MAKE_MOCK0(baz, void()); // not from Interface
};

TEST(exercise_interface_func)
{
  using trompeloeil::_;  // wild card for matching any value
  using trompeloeil::gt; // greater-than match

  Mock m;

  trompeloeil::sequence seq1, seq2;  // control order of matching calls

  int local_var = 0;

  REQUIRE_CALL(m, bar(ANY(int)))     // expect call to m.bar(int)
    .LR_SIDE_EFFECT(local_var = _1)  // set captured variable to value of param
    .RETURN(_1 > 0)                  // return value depending on param value
    .IN_SEQUENCE(seq1)               // must be first match for seq1
    .TIMES(AT_LEAST(1));             // can be called several times

  FORBID_CALL(m, bar(0));            // but m.bar(0) is not allowed

  REQUIRE_CALL(m, bar("word"))       // expect one call to m.bar(std::string)
    .RETURN(true)
    .IN_SEQUENCE(seq2);              // must be first match for seq2

  REQUIRE_CALL(m, foo(gt(2), _))     // expect call to foo(int,std::string&)
    .WITH(_2 == "")                  // with int > 2 and empty string
    .IN_SEQUENCE(seq1, seq2)         // last for both seq1 and seq2
    .SIDE_EFFECT(_2 = "cat")         // and set param string to "cat"
    .RETURN(true);

  interface_func(&m);

  // all the above expectations must be fulfilled here
}

Building and running the self test suite

To build the self test suite run cmake with -DTROMPELOEIL_BUILD_TESTS=yes. Use the options CXX_STANDARD to select which C++ standard to test, and SANITIZE to select sanitizers to build with. Note that the self tests needs a reasonably modern version of CMake. Example:

cmake -B build_dir \
      -D TROMPELOEIL_BUILD_TESTS=yes \
      -D CMAKE_BUILD_TYPE=Debug \
      -D CXX_STANDARD=17 \
      -D SANITIZE=Address,Undefined \
      <trompeloeil source dir>

If the build finds a CMake package for Catch2 it will use that, otherwise it will download a header-only version of Catch2 v2.x.

cmake --build build_dir -t self_test thread_terror custom_recursive_mutex

Then run the built binaries:

./build_dir/self_test && ./build_dir/thread_terror && ./build_dir/custom_recursive_mutex

How to contribute

Contributions are most welcome. For new functionality, please file an issue as an enhancement request first, to get a discussion going about how to best implement it. Also for bugfixes, it is good to file an issue, so that others can see what the problem is and when it's solved. Internal changes are normally not mentioned in the ChangeLog - it should typically reflect what a user can see (however, performance improvements and silencing warnings are visible for users.) Feel free to add your name to the copyright blurb.

|Change | PR to | |-----------------------------|----------------| |Documentation |master branch | |Trivial bugfixes |master branch | |Non trivial bugfixes |develop branch | |Simple new functionality |develop branch | |Non-trivial new functionality|new topic branch|

Compiler compatibility

Trompeloeil is known to work with:

  • GCC 4.8.4+, 4.9.3+, 5, 6, 7, 8, 9, 10, 11, 12, 13
  • Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
  • Visual Studio 2015, 2017, 2019

Latest patch level releases are assumed in the versions listed above.

Further details on C++11 support, platform and library limitations, may be found in

External Tools

Videos

| | | |--|--| | Mocking Modern C++ with Trompeloeil| Mocking Modern C++ with Trompeloeil, introduction to Trompeloeil by Björn Fahller from from from Stockholm C++ UG (34m)| (Slides) | | Using Trompeloeil, a Mocking Framework for Modern C++| Using Trompeloeil, a Mocking Framework for Modern C++, by Björn Fahller from NDC{Oslo} 2017 (52m) (Slides) | | Using Trompeloeil, a Mocking Framework for Modern C++ | Using Trompeloeil, a Mocking Framework for Modern C++, Detailed presentation by Björn Fahller from ACCU 2017 (1h25m) (Slides with extra material) | | Packporting to the future | Backporting to the Future, Detailing the C++11 API and how it came to be, by Andrew Paxie from Pacific++ 2018 (53m) (Slides) |

ORG