Commit 4f8969f5 authored by Torbjørn Ludvigsen's avatar Torbjørn Ludvigsen 👷

Unit test with doctest, single binary

parent c34777c3
......@@ -115,6 +115,8 @@ Build2 is nice, but not widely used, so many will need to skim through it's [doc
to fully control how this project is built and managed.
## Licensing
The cppcore gsl library is MIT licensed, and can be found here: https://github.com/microsoft/GSL
The cppcore Gsl library is MIT licensed, and can be found here: https://github.com/microsoft/GSL
The Eigen library is MPL2.0 licensed and can be found here: https://gitlab.com/libeigen/eigen
The spdlog library is MIT licensed, and can be found here: https://github.com/gabime/spdlog
The Spdlog library is MIT licensed, and can be found here: https://github.com/gabime/spdlog
The Doctest library is MIT licensed and can be found here: https://github.com/onqtam/doctest
hxx{*}: extension = h
lib{doctest}: {hxx ixx txx}{**}
# Export options
lib{doctest}:
{
cxx.export.poptions = "-I$src_root/extern/doctest/"
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,6 +2,7 @@ include ../extern/
include ../extern/eigen/
include ../extern/cppcore/
include ../extern/spdlog-1.6.0/
include ../extern/doctest/
libs =
libs += ../extern/eigen/lib{eigen}
......@@ -10,7 +11,9 @@ libs += ../extern/cppcore/lib{cppcore}
# There is a non-slow version
# Build the static lib inside external/spdlib directory
# Then remove _slow
libs += ../extern/spdlog-1.6.0/lib{spdlog_slow}
libs += ../extern/spdlog-1.6.0/lib{spdlog}
libs += ../extern/doctest/lib{doctest}
# ./ means "when building this dir, also build following target"
# executable linc depends on utility library linc, main.cxx.
......@@ -26,14 +29,14 @@ libs += ../extern/spdlog-1.6.0/lib{spdlog_slow}
libue{linc}: {hxx cxx}{** -**.test... -main} $libs
# All executables ending with .test are tests.
# So they are built and executed with `b test`.
# They are also not installed with `b install`.
exe{*.test}:
{
test = true
install = false
}
## All executables ending with .test are tests.
## So they are built and executed with `b test`.
## They are also not installed with `b install`.
#exe{*.test}:
#{
# test = true
# install = false
#}
# All files ending with <somename>.test.cxx should be compiled
# to executables <somename>.test
......@@ -41,15 +44,36 @@ exe{*.test}:
# If <somename>.test.testscript exist, it is associated with the test executable
# bin.whole = false makes so only the used functions are statically linked
# into the test executable
for t: cxx{**.test...}
{
d = $directory($t)
n = $name($t)...
#for t: cxx{**.test...}
#{
# d = $directory($t)
# n = $name($t)...
# info $d
# info $n
# info +$n
# info $t
#
# ./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n}
# $d/exe{$n}: libue{linc}: bin.whole = false
#}
./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n}
$d/exe{$n}: libue{linc}: bin.whole = false
exe{linc-test}:
{
test = true
install = false
}
./: exe{linc-test}: cxx{*.test.c++} libue{linc}
#exe{linc-test}: libue{linc}: bin.whole = false
#./: exe{linc.test}: cxx{**.test...} libue{linc}
#{
# bin.whole = false
# test = true
# install = false
#}
# Include our own header files
cxx.poptions =+ "-I$out_root" "-I$src_root"
......
#include <iostream>
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
TEST_CASE("Testy test case") {
REQUIRE((1 + 1) == 2);
}
......@@ -21,21 +21,21 @@ EOE
: Small-cube-nonfile-params
: Loading working stl file but non-existent params file
$* "$src_base/small-cube.stl" 'nonofile' &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" 'nonofile' &linc.log 2>>EOE != 0
Failed to open nonofile
Validation of nonofile failed
EOE
: Small-cube-input
: Loading working small stl file
$* "$src_base/small-cube.stl" "$src_base/params" &linc.log > 'No collision detected'
$* "$src_base/test-models/small-cube-ascii.stl" "$src_base/params-example" &linc.log > 'No collision detected'
: Missing-pivot-names
: Checks stderr when only one pivot is described in params file
cat <<EOI >=test.params;
effector-pivot-A1: ( 220.0, -140.0, 130.0)
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Did not find anchor-pivot-A1 in test.params
Did not find anchor-pivot-A2 in test.params
Did not find anchor-pivot-B1 in test.params
......@@ -57,7 +57,7 @@ effector-pivot-A1: ( 220.0, -140.0, 130.0)
effector-pivot-B1: (1220.0, -140.0, 130.0)
effector-pivot-A1: ( 221.0, -140.0, 130.0)
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Found effector-pivot-A1 twice in test.params
Validation of test.params failed
EOE
......@@ -78,7 +78,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
lanchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Did not find effector-pivot-A1 in test.params
Invalid pivot name does not start with 'effector' or 'anchor': beeffector-pivot-A1
Invalid line:
......@@ -102,7 +102,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
lanchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Invalid pivot name does not start with 'effector' or 'anchor': lanchor-pivot-C2
Invalid line:
lanchor-pivot-C2: -1670.30, 611.63, -31.23
......@@ -125,7 +125,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
anchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Did not find effector-pivot-A1 in test.params
Validation of test.params failed
EOE
......@@ -146,7 +146,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
anchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Invalid line:
effector-pivot-A1: 220.0, -140.0
Validation of test.params failed
......@@ -168,7 +168,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
anchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log > 'No collision detected'
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log > 'No collision detected'
: Space-separated-z-coordinate
: Checks behaviour when there's a space in one of the coordinates
......@@ -186,7 +186,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
anchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Could not convert to float: 130.0 999
Could not parse all characters
Invalid line:
......@@ -211,7 +211,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
anchor-pivot-C2: -, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Could not convert to float: -
stof
Invalid line:
......@@ -235,7 +235,7 @@ anchor-pivot-B2: 1317.51, 1540.88, -32.19
anchor-pivot-C1: -1435.30, 1011.60, -31.23
anchor-pivot-C2: -1670.30, 611.63, -31.23
EOI
$* "$src_base/small-cube.stl" test.params &linc.log 2>>EOE != 0
$* "$src_base/test-models/small-cube-ascii.stl" test.params &linc.log 2>>EOE != 0
Invalid line:
effector-pivot-B2: 5.0, 270.0 130.0
Validation of test.params failed
......@@ -244,4 +244,4 @@ EOE
#: Cube-input
#: Analysis detects collision with big object
#$* "$src_base/big-cube.stl" "$src_base/params" > 'Collision detected'
#$* "$src_base/big-cube.stl" "$src_base/params-example" > 'Collision detected'
#include <iostream>
#include <gsl/span_ext>
#include <doctest/doctest.h>
#include <linc/params.h++>
auto tokenizeWellFormedString() -> int {
std::string const inString{"effector-pivot-A1: ( 220, -140.0, 130.0 ) "};
PivotTokens const got = tokenize(inString);
PivotTokens const expected{"effector-pivot-A1", "220", "-140.0", "130.0"};
if (not(got == expected)) {
std::cout << "Expected: " << expected << '\n';
std::cout << "Got: " << got << '\n';
return 1;
}
return 0;
}
auto tokenizeTooManyTokens() -> int {
std::string const inString{"effector-pivot-A1: 220, -140.0, 130.0, 123.4"};
PivotTokens const got = tokenize(inString);
PivotTokens const expected{"effector-pivot-A1", "220", "-140.0", "130.0"};
if (not(got == expected)) {
std::cout << "Expected: " << expected << '\n';
std::cout << "Got: " << got << '\n';
return 1;
}
return 0;
}
auto main(int argc, char **argv) -> int {
// Give testscript some output to assert on
if (argc > 1) {
gsl::span<char *> const args(argv, static_cast<unsigned int>(argc));
auto *const paramsFileName = gsl::at(args, 1);
Pivots pivots{paramsFileName};
std::cout << pivots << '\n';
}
int result = 0;
result += tokenizeWellFormedString();
result += tokenizeTooManyTokens();
return result;
}
TEST_CASE("params test case number 1") { REQUIRE((2 + 2) == 4); }
......@@ -2,8 +2,8 @@
: Checks standard case
:
: Checks what gets printed
: when test executable called with the test params.
$* "$src_base/params" >>EOE
: when test executable called with the params example.
$* "$src_base/params-example" >>EOE
effector:
220 -220 230 5 -5 -230
-140 -140 -130 270 270 -130
......
#include <iostream>
#include <doctest/doctest.h>
#include <linc/params.h++>
auto tokenizeWellFormedString() -> int {
std::string const inString{"effector-pivot-A1: ( 220, -140.0, 130.0 ) "};
PivotTokens const got = tokenize(inString);
PivotTokens const expected{"effector-pivot-A1", "220", "-140.0", "130.0"};
if (not(got == expected)) {
std::cout << "Expected: " << expected << '\n';
std::cout << "Got: " << got << '\n';
return 1;
}
return 0;
}
auto tokenizeTooManyTokens() -> int {
std::string const inString{"effector-pivot-A1: 220, -140.0, 130.0, 123.4"};
PivotTokens const got = tokenize(inString);
PivotTokens const expected{"effector-pivot-A1", "220", "-140.0", "130.0"};
if (not(got == expected)) {
std::cout << "Expected: " << expected << '\n';
std::cout << "Got: " << got << '\n';
return 1;
}
return 0;
}
TEST_CASE("Tokenize well formed string") {
REQUIRE(tokenizeWellFormedString() == 0);
}
TEST_CASE("Tokenize too many tokens") { REQUIRE(tokenizeTooManyTokens() == 0); }
......@@ -22,6 +22,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <Eigen/Geometry>
......@@ -75,6 +76,19 @@ public:
enum class Type { BINARY, ASCII, INMEMORY };
friend std::ostream &operator<<(std::ostream &os, Type const type) {
switch (type) {
case (Type::BINARY):
return os << "BINARY";
case (Type::ASCII):
return os << "ASCII";
case (Type::INMEMORY):
return os << "INMEMORY";
default:
return os << "NONE";
}
}
struct Stats {
char header[LABEL_SIZE + 1] = {0};
Type type = Stl::Type::BINARY;
......
#include <linc/stl.h++>
#include <doctest/doctest.h>
TEST_CASE("small-cube-ascii.stl looks good") {
Stl const stl{"./test-models/small-cube-ascii.stl"};
REQUIRE(stl.m_stats.number_of_facets == 12);
}
#include <cassert>
#include <iostream>
#include <doctest/doctest.h>
auto main() -> int { std::cout << "Hello, Test!" << '\n'; }
TEST_CASE("Triangle mesh test test case") { REQUIRE((1 + 1) == 2); }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment