Static-test - A playground to play with ideas related to testing the comparability of the code

Overview

Static test playground

⚠️ The code is just an experiment. Compiles and runs on Ubuntu 20.04. Work with other systems is not guaranteed. ⚠️

What is a static test

If we want to check that some code does not compile there is no way to write a test for it.

This repo aims at solving this problem.

How it looks to the user

The proposal for the user interface for this feature is to piggyback on GTest pipeline as follows:

#include <gtest/gtest.h>
#include "static_test.h"

STATIC_TEST(foo) {
  Foo foo;
  foo.bar();
  SHOULD_NOT_COMPILE(foo.stuff());
  SHOULD_NOT_COMPILE_WITH_MESSAGE(foo.stuff(), "has no member named 'stuff'");
}

The user is able to write a code to check that some code should not compile. All the code outside of the SHOULD_NOT_COMPILE or SHOULD_NOT_COMPILE_WITH_MESSAGE macros is compiled and run as expected. The compiler will happily report any errors back to the user if they should make any within the STATIC_TEST scope. If the code under SHOULD_NOT_COMPILE ends up actually compiling a runtime error will be issued with a description of this.

This test can be run within this repo as:

./bazelisk test --test_output=all //foo:test_foo

The approximate output of this test if nothing fails would be smth like this:

[----------] 1 test from StaticTest__foo
[ RUN      ] StaticTest__foo.foo
[ COMPILE STATIC TEST ] foo
[                  OK ] foo
[       OK ] StaticTest__foo.foo (966 ms)
[----------] 1 test from StaticTest__foo (966 ms total)

If there is a failure, the line that causes the failure will be printed like so:

[----------] 1 test from StaticTest__FooMixedCorrectAndWrongTest
[ RUN      ] StaticTest__SomeTest.SomeTest
[ COMPILE STATIC TEST ] SomeTest
ERROR: foo/test_foo.cpp:35: must fail to compile but instead compiled without error.
foo/test_foo.cpp:0: Failure
Some of the static tests failed. See above for error.
[              FAILED ] SomeTest
[  FAILED  ] StaticTest__SomeTest.SomeTest (1403 ms)
[----------] 1 test from StaticTest__SomeTest (1403 ms total)

Currently, the code expects to have a compilation database with at the root of the project. This can be generated from a bazel build using the following repository: https://github.com/grailbio/bazel-compilation-database. Just download it anywhere and call the generate.sh script in the folder of this project.

Eventually, we might want to plug this into the build system to make sure we have everything at hand when running the test.

How to check that something fails to compile

We obviously cannot write a normal unit test for this, as if we write code that does not compile it, well, does not compile. The only way I can think of here is to run an external tool.

So the STATIC_TEST macro would expand into a class that will do work in its constructor. It will essentially call an external tool providing it with the name of the static test and a path to the current file utilizing __FILE__. If we know the compilation flags for this file we can write a new temporary cpp file with the contents:

#include <gtest/gtest.h>

#include "foo/foo.h"
#include "static_test/static_test.h"

int main()
{
  Foo foo;
  foo.bar();
  foo.stuff();
  foo.baz();
  return 0;
}

We can then compile this file using all the same compilation flags and check if there is an error that matches the error message regex provided into the message. If there is an error, then we pass the test. If there is no error that matches, we fail the test.

You might also like...
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.

Yolov5 running on TorchServe (GPU compatible) ! This is a dockerfile to run TorchServe for Yolo v5 object detection model. (TorchServe (PyTorch librar

Official Pytorch implementation of
Official Pytorch implementation of "Beyond Static Features for Temporally Consistent 3D Human Pose and Shape from a Video", CVPR 2021

TCMR: Beyond Static Features for Temporally Consistent 3D Human Pose and Shape from a Video Qualtitative result Paper teaser video Introduction This r

A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.

python_graphs This package is for computing graph representations of Python programs for machine learning applications. It includes the following modu

Genshin-assets - 👧 Public documentation & static assets for Genshin Impact data.

genshin-assets This repo provides easy access to the Genshin Impact assets, primarily for use on static sites. Sources Genshin Optimizer - An Artifact

This is the code of using DQN to play Sekiro .

Update for using DQN to play sekiro 2021.2.2(English Version) This is the code of using DQN to play Sekiro . I am very glad to tell that I have writen

Plug and play transformer you can find network structure and official complete code by clicking List

Plug-and-play Module Plug and play transformer you can find network structure and official complete code by clicking List The following is to quickly

Learning from Guided Play: A Scheduled Hierarchical Approach for Improving Exploration in Adversarial Imitation Learning Source Code
Learning from Guided Play: A Scheduled Hierarchical Approach for Improving Exploration in Adversarial Imitation Learning Source Code

Learning from Guided Play: A Scheduled Hierarchical Approach for Improving Exploration in Adversarial Imitation Learning Source Code

Minimal diffusion models - Minimal code and simple experiments to play with Denoising Diffusion Probabilistic Models (DDPMs)

Minimal code and simple experiments to play with Denoising Diffusion Probabilist

Pytorch and Torch testing code of CartoonGAN
Pytorch and Torch testing code of CartoonGAN

CartoonGAN-Test-Pytorch-Torch Pytorch and Torch testing code of CartoonGAN [Chen et al., CVPR18]. With the released pretrained models by the authors,

Comments
  • LICENSE

    LICENSE

    Hi @niosus, I just saw your talk at CppCon2020, very interesting and enlightening. I was looking for a solution to this use-case right 2/3 weeks ago. I was wondering what is the license for this repo.

    Cheers, Mirco

    opened by com2rng 1
Owner
Igor Bogoslavskyi
Researcher interested in LiDAR scene understanding, localization and mapping.
Igor Bogoslavskyi
Static Features Classifier - A static features classifier for Point-Could clusters using an Attention-RNN model

Static Features Classifier This is a static features classifier for Point-Could

ABDALKARIM MOHTASIB 1 Jan 25, 2022
Implementation of E(n)-Transformer, which extends the ideas of Welling's E(n)-Equivariant Graph Neural Network to attention

E(n)-Equivariant Transformer (wip) Implementation of E(n)-Equivariant Transformer, which extends the ideas from Welling's E(n)-Equivariant G

Phil Wang 132 Jan 2, 2023
🏅 The Most Comprehensive List of Kaggle Solutions and Ideas 🏅

?? Collection of Kaggle Solutions and Ideas ??

Farid Rashidi 2.3k Jan 8, 2023
How the Deep Q-learning method works and discuss the new ideas that makes the algorithm work

Deep Q-Learning Recommend papers The first step is to read and understand the method that you will implement. It was first introduced in a 2013 paper

null 1 Jan 25, 2022
City-seeds - A random generator of cultural characteristics intended to spark ideas and help draw threads

City Seeds This is a random generator of cultural characteristics intended to sp

Aydin O'Leary 2 Mar 12, 2022
QueryFuzz implements a metamorphic testing approach to test Datalog engines.

Datalog is a popular query language with applications in several domains. Like any complex piece of software, Datalog engines may contain bugs. The mo

null 34 Sep 10, 2022
CIFAR-10_train-test - training and testing codes for dataset CIFAR-10

CIFAR-10_train-test - training and testing codes for dataset CIFAR-10

Frederick Wang 3 Apr 26, 2022
This is our ARTS test set, an enriched test set to probe Aspect Robustness of ABSA.

This is the repository for our 2020 paper "Tasty Burgers, Soggy Fries: Probing Aspect Robustness in Aspect-Based Sentiment Analysis". Data We provide

null 35 Nov 16, 2022
This repository is related to an Arabic tutorial, within the tutorial we discuss the common data structure and algorithms and their worst and best case for each, then implement the code using Python.

Data Structure and Algorithms with Python This repository is related to the Arabic tutorial here, within the tutorial we discuss the common data struc

Mohamed Ayman 33 Dec 2, 2022
All the code and files related to the MI-Lab of UE19CS305 course in sem 5

Machine-Intelligence-Lab-CS305 The compilation of all the code an drelated files from MI-Lab UE19CS305 (of batch 2019-2023) offered by PES University

Arvind Krishna 3 Nov 10, 2022