library testing infrastructure

This commit is contained in:
Alexey Fedoseev
2024-04-13 23:48:48 +03:00
parent 8303a2de9b
commit 1e19813fd2
5 changed files with 184 additions and 9 deletions

View File

@@ -7,11 +7,15 @@ else
LIB_TARGET := $(LIB_TARGET_STATIC)
endif
TEST_TARGET := cyberiadapp_test
TESTS_DIR := tests
MAIN_TARGET := cyberiadapp
LIB_SOURCES := cyberiadamlpp.cpp
TEST_SOURCES := main.cpp
MAIN_SOURCES := main.cpp
LIB_OBJECTS := $(patsubst %.cpp, %.o, $(LIB_SOURCES))
MAIN_OBJECTS := $(patsubst %.cpp, %.o, $(MAIN_SOURCES))
TEST_SOURCES := $(wildcard $(addsuffix /*.cpp, $(TESTS_DIR)))
TEST_OBJECTS := $(patsubst %.cpp, %.o, $(TEST_SOURCES))
TEST_TARGETS := $(patsubst %.cpp, %.test, $(TEST_SOURCES))
ifeq ($(DEBUG), 1)
CFLAGS := -Wall -Wshadow -Wconversion -fPIC -g3 -D__DEBUG__
@@ -23,7 +27,7 @@ endif
INCLUDE := -I. -I/usr/include/libxml2 -I./cyberiadaml
LIBS := -L/usr/lib -lxml2 -L./cyberiadaml -lcyberiadaml
TEST_LIBS := -L. -lcyberiadamlpp
MAIN_LIBS := -L. -lcyberiadamlpp
$(LIB_TARGET): $(LIB_OBJECTS)
ifeq ($(DYNAMIC), 1)
@@ -32,17 +36,24 @@ else
ar rcs $@ $(LIB_OBJECTS)
endif
$(TEST_TARGET): $(TEST_OBJECTS) $(LIB_TARGET) $(LIB_ORJECTS)
g++ $(TEST_OBJECTS) -Wl,-\( $(LIBS) $(TEST_LIBS) -Wl,-\) -o $@
$(MAIN_TARGET): $(MAIN_OBJECTS) $(LIB_TARGET) $(LIB_ORJECTS)
g++ $(MAIN_OBJECTS) -Wl,-\( $(LIBS) $(MAIN_LIBS) -Wl,-\) -o $@
%.test: %.o
g++ $< -Wl,-\( $(LIBS) $(MAIN_LIBS) -Wl,-\) -o $@
%.o: %.cpp
g++ -c $< $(CFLAGS) $(INCLUDE) -o $@
clean:
rm -f *~ *.o $(TARGET) $(TEST_TARGET) $(LIB_TARGET_STATIC) $(LIB_TARGET_DYNAMIC)
rm -f *~ *.o $(TARGET) $(MAIN_TARGET) $(LIB_TARGET_STATIC) $(LIB_TARGET_DYNAMIC)
rm -f $(TESTS_DIR)/*~ $(TESTS_DIR)/*.o $(TESTS_DIR)/*.test.graphml $(TESTS_DIR)/*.test.txt $(TEST_TARGETS)
main: $(TEST_TARGET)
main: $(MAIN_TARGET)
all: $(LIB_TARGET) $(TEST_TARGET)
tests: $(TEST_TARGETS)
@echo >/dev/null
.PHONY: all clean main
all: $(LIB_TARGET) $(MAIN_TARGET) $(TEST_TARGETS)
.PHONY: all clean main tests

50
run-tests.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
DEBUG=1 make
DEBUG=1 make tests
if [ $? != 0 ]
then
echo "make test failed!"
exit 1
fi
echo
echo "tests ready!"
echo
for t in $(ls tests/*.test); do
num=$(echo $t | grep -Poe '\d+')
echo -n "$num $t... "
if [ -f "tests/$num-input.graphml" ]
then
$t > "$t.txt"
else
$t
fi
if [ $? != 0 ]
then
echo "test run failed!"
exit 2
fi
if [ -f "tests/$num-output.graphml" ]
then
diff "$t.graphml" "tests/$num-output.graphml" >/dev/null
if [ $? != 0 ]
then
echo "test failed: graphml file didn't match the pattern!"
exit 3
fi
fi
if [ -f "tests/$num-output.txt" ]
then
diff "$t.txt" "tests/$num-output.txt" >/dev/null
if [ $? != 0 ]
then
echo "test failed: output didn't match the pattern!"
exit 3
fi
fi
echo "ok"
done
exit 0

View File

@@ -0,0 +1,38 @@
/* -----------------------------------------------------------------------------
* The Cyberiada GraphML C++ library implemention
*
* The test
*
* Copyright (C) 2024 Alexey Fedoseev <aleksey@fedoseev.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/
* ----------------------------------------------------------------------------- */
#include <iostream>
#include "cyberiadamlpp.h"
using namespace Cyberiada;
using namespace std;
int main(int argc, char** argv)
{
Document d;
try {
d.save(string(argv[0]) + ".graphml", formatCyberiada10);
} catch (const Cyberiada::ParametersException&) {
return 0;
} catch (const Cyberiada::Exception&) {
}
return 1;
}

View File

@@ -0,0 +1,38 @@
/* -----------------------------------------------------------------------------
* The Cyberiada GraphML C++ library implemention
*
* The test
*
* Copyright (C) 2024 Alexey Fedoseev <aleksey@fedoseev.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/
* ----------------------------------------------------------------------------- */
#include <iostream>
#include "cyberiadamlpp.h"
using namespace Cyberiada;
using namespace std;
int main(int argc, char** argv)
{
Document d;
d.new_state_machine("SM");
try {
d.save(string(argv[0]) + ".graphml", formatCyberiada10);
} catch (const Cyberiada::Exception&) {
return 1;
}
return 0;
}

38
tests/02-output.graphml Normal file
View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns">
<data key="gFormat">Cyberiada-GraphML-1.0</data>
<key id="gFormat" for="graphml" attr.name="format" attr.type="string"/>
<key id="dName" for="graph" attr.name="name" attr.type="string"/>
<key id="dName" for="node" attr.name="name" attr.type="string"/>
<key id="dStateMachine" for="graph" attr.name="stateMachine" attr.type="string"/>
<key id="dSubmachineState" for="node" attr.name="submachineState" attr.type="string"/>
<key id="dGeometry" for="graph" attr.name="geometry"/>
<key id="dGeometry" for="node" attr.name="geometry"/>
<key id="dGeometry" for="edge" attr.name="geometry"/>
<key id="dSourcePoint" for="edge" attr.name="sourcePoint"/>
<key id="dTargetPoint" for="edge" attr.name="targetPoint"/>
<key id="dLabelGeometry" for="edge" attr.name="labelGeometry"/>
<key id="dNote" for="node" attr.name="note" attr.type="string"/>
<key id="dVertex" for="node" attr.name="vertex" attr.type="string"/>
<key id="dData" for="node" attr.name="data" attr.type="string"/>
<key id="dData" for="edge" attr.name="data" attr.type="string"/>
<key id="dMarkup" for="node" attr.name="markup" attr.type="string"/>
<key id="dColor" for="node" attr.name="color" attr.type="string"/>
<key id="dColor" for="edge" attr.name="color" attr.type="string"/>
<key id="dPivot" for="edge" attr.name="pivot" attr.type="string"/>
<key id="dChunk" for="edge" attr.name="chunk" attr.type="string"/>
<graph id="G0" edgedefault="directed">
<data key="dName">SM</data>
<node id="nMeta">
<data key="dNote">formal</data>
<data key="dName">CGML_META</data>
<data key="dData">standardVersion/ 1.0
transitionOrder/ transitionFirst
eventPropagation/ propagate
</data>
</node>
</graph>
</graphml>