Add testcases for plugin with doctest usage

This commit is contained in:
Christian Kreibich 2021-07-08 12:32:50 -07:00
parent 5c44dfbb9e
commit 78803b04fc
11 changed files with 113 additions and 0 deletions

View file

@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
doctest-plugin/demotest

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[doctest] doctest version is "x.y.z"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases: 1 | 1 passed | 0 failed | XX skipped
[doctest] assertions: 1 | 1 passed | 0 failed |
[doctest] Status: SUCCESS!

View file

@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.

View file

@ -0,0 +1,12 @@
# This requires Zeek with unit test support. The following errors if disabled.
# @TEST-REQUIRES: zeek --test -h >/dev/null
# @TEST-EXEC: ${DIST}/auxil/zeek-aux/plugin-support/init-plugin -u . Demo Doctest
# @TEST-EXEC: cp -r %DIR/doctest-plugin/* .
# Build the plugin without unit-test support.
# @TEST-EXEC: ./configure --disable-cpp-tests --zeek-dist=${DIST} && make
#
# List the plugin's test names -- there shouldn't be any.
# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Demo::Doctest" ZEEK_PLUGIN_PATH=`pwd` zeek --test -ltc | grep doctest-plugin >testnames || true
# @TEST-EXEC: btest-diff testnames

View file

@ -0,0 +1,25 @@
#include "Plugin.h"
#include <zeek/3rdparty/doctest.h>
namespace btest::plugin::Demo_Doctest { Plugin plugin; }
using namespace btest::plugin::Demo_Doctest;
zeek::plugin::Configuration Plugin::Configure()
{
zeek::plugin::Configuration config;
config.name = "Demo::Doctest";
config.description = "Run doctest in a unit-test enabled build";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}
TEST_CASE("doctest-plugin/demotest")
{
CHECK(true);
}

View file

@ -0,0 +1,17 @@
#pragma once
#include <zeek/plugin/Plugin.h>
namespace btest::plugin::Demo_Doctest {
class Plugin : public zeek::plugin::Plugin
{
protected:
// Overridden from zeek::plugin::Plugin.
zeek::plugin::Configuration Configure() override;
};
extern Plugin plugin;
}

View file

@ -0,0 +1,18 @@
# This requires Zeek with unit test support. The following errors if disabled.
# @TEST-REQUIRES: zeek --test -h >/dev/null
# @TEST-EXEC: ${DIST}/auxil/zeek-aux/plugin-support/init-plugin -u . Demo Doctest
# @TEST-EXEC: cp -r %DIR/doctest-plugin/* .
# Build the plugin with unit-test support. Zeek supports it, so we should
# get runnable tests.
# @TEST-EXEC: ./configure --zeek-dist=${DIST} && make
#
# List the plugin's test names.
# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Demo::Doctest" ZEEK_PLUGIN_PATH=`pwd` zeek --test -ltc | grep doctest-plugin >testnames
# @TEST-EXEC: btest-diff testnames
# The seed file affects some of the unit tests, so we unset it.
# Running the unit tests implies deterministic mode, -D.
# @TEST-EXEC: ZEEK_SEED_FILE= ZEEK_PLUGIN_ACTIVATE="Demo::Doctest" ZEEK_PLUGIN_PATH=`pwd` zeek --test --test-case='doctest-plugin/*' >testresults
# @TEST-EXEC: TEST_DIFF_CANONIFIER=diff-clean-doctest btest-diff testresults

View file

@ -0,0 +1,13 @@
# This requires Zeek without unit test support. The following errors if enabled.
# @TEST-REQUIRES: ! zeek --test -h >/dev/null
# @TEST-EXEC: ${DIST}/auxil/zeek-aux/plugin-support/init-plugin -u . Demo Doctest
# @TEST-EXEC: cp -r %DIR/doctest-plugin/* .
# Build the plugin without disabling unit testing. Zeek doesn't support it,
# so the plugin should automatically build without it.
# @TEST-EXEC: ./configure --zeek-dist=${DIST} && make
#
# List the plugin's test names -- there shouldn't be any.
# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Demo::Doctest" ZEEK_PLUGIN_PATH=`pwd` zeek --test -ltc | grep doctest-plugin >testnames || true
# @TEST-EXEC: btest-diff testnames

View file

@ -0,0 +1,17 @@
#! /usr/bin/env bash
#
# doctest's console reports contain several aspects that change over time:
# - The total number of tests, which we replace with "XX"
# - The version number, which becomes "x.y.z"
# - Spacing in the report, which we normalize to single spaces
# Get us "modern" regexps with sed.
if [ $(uname) == "Linux" ]; then
sed="sed -r"
else
sed="sed -E"
fi
$sed -e 's/[0-9]+ skipped/XX skipped/g' |
$sed -e 's/"[0-9]+\.[0-9]+\.[0-9]+"/"x.y.z"/g' |
$sed -e 's/ {2,}/ /g'