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.

Owner
Igor Bogoslavskyi
Researcher interested in LiDAR scene understanding, localization and mapping.
Igor Bogoslavskyi
Official Implementation (PyTorch) of "Point Cloud Augmentation with Weighted Local Transformations", ICCV 2021

PointWOLF: Point Cloud Augmentation with Weighted Local Transformations This repository is the implementation of PointWOLF(To appear). Sihyeon Kim1*,

MLV Lab (Machine Learning and Vision Lab at Korea University) 16 Nov 03, 2022
Code to go with the paper "Decentralized Bayesian Learning with Metropolis-Adjusted Hamiltonian Monte Carlo"

dblmahmc Code to go with the paper "Decentralized Bayesian Learning with Metropolis-Adjusted Hamiltonian Monte Carlo" Requirements: https://github.com

1 Dec 17, 2021
Experiments on Flood Segmentation on Sentinel-1 SAR Imagery with Cyclical Pseudo Labeling and Noisy Student Training

Flood Detection Challenge This repository contains code for our submission to the ETCI 2021 Competition on Flood Detection (Winning Solution #2). Acco

Siddha Ganju 108 Dec 28, 2022
EgGateWayGetShell py脚本

EgGateWayGetShell_py 免责声明 由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任。 使用 python3 eg.py urls.txt 目标 title:锐捷网络-EWEB网管系统 port:4430 漏洞成因 ?p

榆木 61 Nov 09, 2022
CSPML (crystal structure prediction with machine learning-based element substitution)

CSPML (crystal structure prediction with machine learning-based element substitution) CSPML is a unique methodology for the crystal structure predicti

8 Dec 20, 2022
A Fast Knowledge Distillation Framework for Visual Recognition

FKD: A Fast Knowledge Distillation Framework for Visual Recognition Official PyTorch implementation of paper A Fast Knowledge Distillation Framework f

Zhiqiang Shen 129 Dec 24, 2022
A Tensorflow based library for Time Series Modelling with Gaussian Processes

Markovflow Documentation | Tutorials | API reference | Slack What does Markovflow do? Markovflow is a Python library for time-series analysis via prob

Secondmind Labs 24 Dec 12, 2022
Author Disambiguation using Knowledge Graph Embeddings with Literals

Author Name Disambiguation with Knowledge Graph Embeddings using Literals This is the repository for the master thesis project on Knowledge Graph Embe

12 Oct 19, 2022
Official implementation of Self-supervised Graph Attention Networks (SuperGAT), ICLR 2021.

SuperGAT Official implementation of Self-supervised Graph Attention Networks (SuperGAT). This model is presented at How to Find Your Friendly Neighbor

Dongkwan Kim 127 Dec 28, 2022
LQM - Improving Object Detection by Estimating Bounding Box Quality Accurately

Improving Object Detection by Estimating Bounding Box Quality Accurately Abstract Object detection aims to locate and classify object instances in ima

IM Lab., POSTECH 0 Sep 28, 2022
Differentiable architecture search for convolutional and recurrent networks

Differentiable Architecture Search Code accompanying the paper DARTS: Differentiable Architecture Search Hanxiao Liu, Karen Simonyan, Yiming Yang. arX

Hanxiao Liu 3.7k Jan 09, 2023
A Python script that creates subtitles of a given length from text paragraphs that can be easily imported into any Video Editing software such as FinalCut Pro for further adjustments.

Text to Subtitles - Python This python file creates subtitles of a given length from text paragraphs that can be easily imported into any Video Editin

Dmytro North 9 Dec 24, 2022
2021 Artificial Intelligence Diabetes Datathon

A.I.D.D. 2021 2021 Artificial Intelligence Diabetes Datathon A.I.D.D. 2021은 ‘2021 인공지능 학습용 데이터 구축사업’을 통해 만들어진 학습용 데이터를 활용하여 당뇨병을 효과적으로 예측할 수 있는가에 대한 A

2 Dec 27, 2021
Automatic library of congress classification, using word embeddings from book titles and synopses.

Automatic Library of Congress Classification The Library of Congress Classification (LCC) is a comprehensive classification system that was first deve

Ahmad Pourihosseini 3 Oct 01, 2022
Python implementation of "Single Image Haze Removal Using Dark Channel Prior"

##Dependencies pillow(~2.6.0) Numpy(~1.9.0) If the scripts throw AttributeError: __float__, make sure your pillow has jpeg support e.g. try: $ sudo ap

Joyee Cheung 73 Dec 20, 2022
The official implementation for "FQ-ViT: Fully Quantized Vision Transformer without Retraining".

FQ-ViT [arXiv] This repo contains the official implementation of "FQ-ViT: Fully Quantized Vision Transformer without Retraining". Table of Contents In

132 Jan 08, 2023
TaCL: Improving BERT Pre-training with Token-aware Contrastive Learning

TaCL: Improving BERT Pre-training with Token-aware Contrastive Learning Authors: Yixuan Su, Fangyu Liu, Zaiqiao Meng, Lei Shu, Ehsan Shareghi, and Nig

Yixuan Su 79 Nov 04, 2022
Bachelor's Thesis in Computer Science: Privacy-Preserving Federated Learning Applied to Decentralized Data

federated is the source code for the Bachelor's Thesis Privacy-Preserving Federated Learning Applied to Decentralized Data (Spring 2021, NTNU) Federat

Dilawar Mahmood 25 Nov 30, 2022
InsightFace: 2D and 3D Face Analysis Project on MXNet and PyTorch

InsightFace: 2D and 3D Face Analysis Project on MXNet and PyTorch

Deep Insight 13.2k Jan 06, 2023
Python implementation of the multistate Bennett acceptance ratio (MBAR)

pymbar Python implementation of the multistate Bennett acceptance ratio (MBAR) method for estimating expectations and free energy differences from equ

Chodera lab // Memorial Sloan Kettering Cancer Center 169 Dec 02, 2022