Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F2718192
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 15, 5:09 PM
Size
25 KB
Mime Type
text/x-diff
Expires
Tue, Feb 17, 5:09 PM (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
237793
Attached To
rXR Xreate
View Options
diff --git a/config/default.json b/config/default.json
index 9ce4b3c..1b714c4 100644
--- a/config/default.json
+++ b/config/default.json
@@ -1,74 +1,74 @@
{
"containers": {
"id": {
"implementations": "containers_impl",
"linkedlist": "linkedlist"
},
"impl": {
"solid": "solid",
"onthefly": "onthefly"
}
},
"logging": {
"id": "logging"
},
"function-entry": "entry",
"transcend": {
"bindings" : {
"variable": "bind",
"function": "bind_func",
"scope": "bind_scope",
"function_demand" : "bind_function_demand",
"scope_decision": "bind_scope_decision"
},
"context" : {
"decisions":{
"dependent": "resolution_dependency"
}
},
"nonevalue": "nonevalue",
"ret": {
"symbol": "retv",
"tag": "ret"
}
},
"tests": {
"template": "troubleshooting",
"templates": {
- "troubleshooting":"-Latex.*:*.Doc_*",
+ "troubleshooting":"Example.Example1",
"documentation":"Modules.Doc_*:Modules_API.Doc_*:Interpretation.Doc_*:AST.Doc_*:Loop.Doc_*:LateReasoning.Doc_*:Latex.Doc_*:Polymorphs.Doc_*:Transcend.Doc_*:ASTCorrespondence.Doc_*:Virtualization.Doc_*:Exploitation.Doc_*:Communication.Doc_*:Introduction.*",
"default": "*",
"ast": "AST.*",
"effects": "Effects.*",
"basic": "Attachments.*",
"compilation": "Compilation.*",
"communication": "Communication.*",
"cfa": "CFA.*",
"containers": "Containers.*",
"dfa": "DFA.*",
"diagnostic": "Diagnostic.*",
"dsl": "Association.*:Interpretation.*",
"exploitation": "Exploitation.*",
"ExpressionSerializer": "ExpressionSerializer.*",
"externc": "InterfaceExternC.*",
"loops": "Loop.*",
"latereasoning": "LateReasoning.*",
"latex": "Latex.*",
"modules": "Modules.*",
"polymorphs": "Polymorphs.*",
"intrinsic-query": "Types.SlaveTypes*:Association.TypedQuery*",
"types": "Types.*",
"virtualization": "Virtualization.*",
"vendorsAPI/clang": "ClangAPI.*",
"vendorsAPI/xml2": "libxml2.*"
}
}
}
diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt
index 8d6a2e4..2890e4b 100644
--- a/cpp/tests/CMakeLists.txt
+++ b/cpp/tests/CMakeLists.txt
@@ -1,59 +1,60 @@
cmake_minimum_required(VERSION 2.8.11)
project(xreate-tests)
find_package(GTest REQUIRED)
INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
INCLUDE_DIRECTORIES("/usr/include/libxml2")
INCLUDE_DIRECTORIES($<TARGET_PROPERTY:xreate,INCLUDE_DIRECTORIES>)
# TESTS
#=========================
FIND_PACKAGE (LLVM REQUIRED)
message("LLVM_LIBRARY_DIRS: " ${LLVM_LIBRARY_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
set (LIBCLASP_PATH ${POTASSCO_PATH}/build/debug)
link_directories(${LIBCLASP_PATH})
#aux_source_directory(. TEST_FILES)
set(TEST_FILES
introduction.cpp
+ unit-test-example.cpp
transcend-ast.cpp
supplemental/docutils
latetranscend.cpp
cfa.cpp
latex.cpp
polymorph.cpp
transcend.cpp
virtualization.cpp
exploitation.cpp
effects-communication.cpp
association.cpp
main.cpp
modules.cpp
attachments.cpp
ast.cpp
dfa.cpp
compilation.cpp
ExpressionSerializer.cpp
externc.cpp
types.cpp
#vendorsAPI/clangAPI.cpp
#vendorsAPI/xml2.cpp
#vendorsAPI/json.cpp
containers.cpp
interpretation.cpp
loops.cpp
#supplemental/versions-algorithm-data_dependency.cpp
effects-versions.cpp
)
add_executable(${PROJECT_NAME} ${TEST_FILES})
target_link_libraries(${PROJECT_NAME} xreate ${GTEST_LIBRARIES} pthread xml2 gcov)
add_custom_target (coverage
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/code-coverage.sh
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
diff --git a/cpp/tests/latex.cpp b/cpp/tests/latex.cpp
index a8d3cec..77db129 100644
--- a/cpp/tests/latex.cpp
+++ b/cpp/tests/latex.cpp
@@ -1,334 +1,328 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* Author: pgess <v.melnychenko@xreate.org>
* Created on June 25, 2018, 5:42 PM
*
* \file latex.cpp
* \brief Testing of latex
*/
#include "xreatemanager.h"
#include "pass/compilepass.h"
#include "transcendlayer.h"
#include "query/latex.h"
#include "compilation/latex.h"
#include "aux/xreatemanager-decorators.h"
#include "compilation/scopedecorators.h"
#include "llvmlayer.h"
#include "supplemental/docutils.h"
#include <boost/format.hpp>
#include <gtest/gtest.h>
using namespace xreate::latex;
using namespace xreate::latereasoning;
using namespace xreate::compilation;
using namespace xreate;
using namespace std;
TEST(Latex, Script_NestedScopePropagation_1) {
std::string program =
R"CODE(
import raw("scripts/cfa/context.lp").
fn = function:: int; entry
{
context:: test1.
if(1==11)::int {2} else {3}
}
)CODE";
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
CodeScope* blockTrue = man->root->findFunction("fn")->getEntryScope()->getBody().blocks.front();
auto blockTrueP = man->transcend->pack(blockTrue);
boost::format formatAlias("alias(%1%, %2%).");
man->transcend->addRawScript((formatAlias % blockTrueP % "block1").str());
man->transcend->addRawScript(
R"SCRIPT(
success1:- bind_scope(Block1, test1, strong); alias(Block1, block1).
)SCRIPT");
man->analyse();
ASSERT_EQ(1, man->transcend->query("success1").size());
}
TEST(Latex, Script_DemAndDecision_1) {
std::string program =
R"CODE(
import raw("scripts/cfa/context.lp").
a = function:: int
{
context:: forC(a).
c()
}
b = function:: int
{
context:: forC(b).
c()
}
c = function:: int {0}
main = function:: int; entry
{
a() + b()
}
)CODE";
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
CodeScope* blockC = man->root->findFunction("c")->getEntryScope();
auto blockCP = man->transcend->pack(blockC);
boost::format formatAlias("alias(%1%, %2%).");
man->transcend->addRawScript((formatAlias % blockCP % "blockC").str());
man->transcend->addRawScript(
R"SCRIPT(
latex_scope_demand(BlockC, forC):- alias(BlockC, blockC).
latex_registered_subjects(forC, Variant):- bind_scope(_, Variant, strong); Variant = forC(_).
)SCRIPT");
man->analyse();
ASSERT_EQ(1, man->transcend->query("latex_fn_demand").size());
ASSERT_EQ(2, man->transcend->query("latex_decision").size());
}
TEST(Latex, LatexQuery_getFnDemand_1){
std::string program =
R"CODE(
import raw("scripts/cfa/context.lp").
main = function:: int; entry
{
context:: alias(blockMain).
0
}
)CODE";
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
man->transcend->addRawScript(
R"SCRIPT(
latex_scope_demand(BlockC, forC):- bind_scope(BlockC, alias(blockMain), strong).
latex_registered_subjects(forC, decisionSome).
)SCRIPT");
LatexQuery* query = new LatexQuery();
man->transcend->registerQuery(query, QueryId::LatexQuery);
man->analyse();
Demand demand = query->getFnDemand("main");
ASSERT_EQ(1, demand.size());
ASSERT_STREQ("forC", demand.front().c_str());
}
TEST(Latex, LatexQuery_getDecision_static_1){
std::string program =
R"CODE(
import raw("scripts/cfa/context.lp").
a = function:: int {context::decisionSome. c()}
b = function:: int {c()}
c = function:: int {context:: alias(blockC). 0}
)CODE";
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
man->transcend->addRawScript(
R"SCRIPT(
latex_scope_demand(BlockC, forC):- bind_scope(BlockC, alias(blockC), strong).
latex_registered_subjects(forC, decisionSome).
)SCRIPT");
LatexQuery* query = new LatexQuery();
man->transcend->registerQuery(query, QueryId::LatexQuery);
man->analyse();
LateAnnotation decisionLA = query->getDecision("forC", man->root->findFunction("a")->getEntryScope());
auto decisionGS = decisionLA.select({}, man->root, man->transcend);
ASSERT_TRUE(decisionGS);
decisionGS->print(cout);
cout << endl;
auto decisionTuple = man->transcend->parse<Gringo::Symbol, Gringo::Symbol, string>(*decisionGS);
string decision = get<2>(decisionTuple);
ASSERT_STREQ("decisionSome", decision.c_str());
}
TEST(Latex, Compilation_1) {
std::string program =
R"CODE(
a = function:: int
{0}
main = function:: int; entry
{
a()
}
)CODE";
string script =
R"SCRIPT(
latex_fn_demand(%1%, subject1).
latex_decision(%2%, subject1, 5).
latex_registered_subjects(subject1, 1).
latex_registered_subjects(subject1, 5).
)SCRIPT";
typedef LatexBruteFunctionDecorator<compilation::BasicFunctionUnit> FnImpl;
typedef LatexBruteScopeDecorator<compilation::CachedScopeDecorator<compilation::BasicCodeScopeUnit>> ScopeImpl;
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
ScopePacked scopeMainP = man->transcend->pack(man->root->findFunction("main")->getEntryScope());
boost::format format(script);
man->transcend->addRawScript((format % "a" % scopeMainP).str());
man->transcend->registerQuery(new LatexQuery(), QueryId::LatexQuery);
man->analyse();
std::unique_ptr<CompilePass> compiler(new compilation::CompilePassCustomDecorators<FnImpl, ScopeImpl>(man.get()));
compiler->run();
man->llvm->initJit();
int(*fnMain)() = (int(*)())man->llvm->getFunctionPointer(compiler->getEntryFunction());
ASSERT_EQ(0, fnMain());
}
//
//TEST(Latex, Full1) {
// std::string program =
// R"CODE(
// import raw("scripts/cfa/context.lp").
//
// a = function:: int
// {
// context:: forC(a).
// c()
// }
//
// b = function:: int
// {
// context:: forC(b).
// c()
// }
//
// c = function:: int {0}
//
// main = function:: int; entry
// {
// a() + b()
// }
// )CODE";
//
// string script =
// R"SCRIPT(
// alias(%1%, scopeC).
// latex_scope_demand(ScopeC, forC) :- alias(ScopeC, scopeC).
// latex_registered_subjects(forC, forC(a)).
// latex_registered_subjects(forC, forC(b)).
// )SCRIPT";
//
// typedef LatexBruteFunctionDecorator<compilation::BasicFunctionUnit> FnImpl;
// typedef LatexBruteScopeDecorator<compilation::CachedScopeDecorator<compilation::BasicCodeScopeUnit>> ScopeImpl;
//
// std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
// ScopePacked scopeMainP = man->transcend->pack(man->root->findFunction("main")->getEntryScope());
// auto scopeCP = man->transcend->pack(man->root->findFunction("c")->getEntryScope());
// boost::format format(script);
// man->transcend->addRawScript((format %scopeCP).str());
// man->transcend->registerQuery(new LatexQuery(), QueryId::LatexQuery);
// man->analyse();
//
// std::unique_ptr<CompilePass> compiler(new compilation::CompilePassCustomDecorators<FnImpl, ScopeImpl>(man.get()));
// compiler->run();
// man->llvm->print();
//}
//
TEST(Latex, Compilation_TransitFn1){
std::string program =
R"CODE(
import raw("scripts/cfa/context.lp").
branchA = function:: int
{
context:: sink_a.
fnTransit()
}
branchB = function:: int
{
context:: sink_b.
fnTransit()
}
fnSink = function:: int {0}
fnTransit = function:: int {fnSink()}
main = function:: int; entry
{
branchA() + branchB()
}
)CODE";
string script =
R"SCRIPT(
alias(scopeSink, %1%).
latex_scope_demand(ScopeSink, sink):- alias(scopeSink, ScopeSink).
latex_registered_subjects(sink, sink_a).
latex_registered_subjects(sink, sink_b).
)SCRIPT";
typedef LatexBruteFunctionDecorator<compilation::BasicFunctionUnit> FnImpl;
typedef LatexBruteScopeDecorator<compilation::CachedScopeDecorator<compilation::BasicCodeScopeUnit>> ScopeImpl;
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
CodeScope* scopeSink = man->root->findFunction("fnSink")->getEntryScope();
auto scopeSinkP = man->transcend->pack(scopeSink);
ScopedSymbol argLatexSS{1, -1};
Symbol argLatexS{argLatexSS, scopeSink};
man->transcend->pack(argLatexS);
boost::format format(script);
man->transcend->addRawScript((format %scopeSinkP).str());
man->transcend->registerQuery(new LatexQuery(), QueryId::LatexQuery);
man->analyse();
std::unique_ptr<CompilePass> compiler(new compilation::CompilePassCustomDecorators<FnImpl, ScopeImpl>(man.get()));
compiler->run();
man->llvm->print();
man->llvm->initJit();
int(*fnMain)() = (int(*)()) man->llvm->getFunctionPointer(compiler->getEntryFunction());
int valueActual = fnMain();
ASSERT_EQ(0, valueActual);
}
TEST(Latex, Doc_Examples1){
std::string program = getDocumentationExampleById("documentation/Concepts/context.xml", "Examples_1");
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
}
TEST(Latex, Doc_Examples2){
std::string program = getDocumentationExampleById("documentation/Concepts/context.xml", "Examples_2");
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
}
TEST(Latex, Doc_ContextPropagation1){
std::string program =getDocumentationExampleById("documentation/Concepts/context.xml", "ContextPropagation1");
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
}
TEST(Latex, Doc_ContextPropagation2){
std::string program = getDocumentationExampleById("documentation/Concepts/context.xml", "ContextPropagation2");
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
}
-TEST(Latex, Doc_ContextPropagation3){
- std::string program = getDocumentationExampleById("documentation/Concepts/context.xml", "ContextPropagation3");
-
- std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
-}
-
TEST(Latex, Doc_Latex1){
std::string program = getDocumentationExampleById("documentation/Concepts/context.xml", "Latex1");
std::unique_ptr<details::tier1::XreateManager> man(details::tier1::XreateManager::prepare(move(program)));
}
\ No newline at end of file
diff --git a/documentation/build.xml b/documentation/build.xml
index 0b10cee..2f61382 100644
--- a/documentation/build.xml
+++ b/documentation/build.xml
@@ -1,154 +1,275 @@
<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.1" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<?xxe-sn 2ckdfwgr1fk 1?>
<title><?xxe-sn 2ckdfwgr1fk 2?>Installation</title>
<section>
<?xxe-sn 2ckdfwgr1fk 6?>
<title><?xxe-sn 2ckdfwgr1fk 7?>Build on Linux</title>
<para><?xxe-sn 2ckdfwgr1fk 8?>Major dependencies:</para>
<itemizedlist>
<?xxe-sn 2ckdfwgr1fk 9?>
<listitem>
<?xxe-sn 2ckdfwgr1fk a?>
<para><?xxe-sn 2ckdfwgr1fk b?>gcc 7</para>
</listitem>
<listitem>
<?xxe-sn 2ckdfwgr1fk c?>
<para><?xxe-sn 2ckdfwgr1fk d?>llvm 5, clang 5</para>
</listitem>
<listitem>
<?xxe-sn 2ckdfwgr1fk e?>
<para><?xxe-sn 2ckdfwgr1fk f?>boost 1.66</para>
</listitem>
<listitem>
<?xxe-sn 2ckdfwgr1fk g?>
<para><?xxe-sn 2ckdfwgr1fk h?>coco</para>
</listitem>
<listitem>
<?xxe-sn 2ckdfwgr1fk i?>
<para><?xxe-sn 2ckdfwgr1fk j?>clingo</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 2ckdfwgr1fk k?>Building tested on <emphasis
role="bold"><?xxe-sn 2ckdfwgr1fk l?>OpenSuse Leap 15</emphasis>. Please
change commands accordingly if using other distributions.</para>
<para><?xxe-sn 2ckdfwgr1fk m?>Pull sources directly from
repository:</para>
- <literallayout><?xxe-sn 2ckdfwgr1fk n?>git clone --recursive https://pgess@bitbucket.org/pgess/xreate.git</literallayout>
+ <literallayout><?xxe-sn 2ckdfwgr1fk n?>git clone --recursive http://xreate.org/diffusion/XR/xreate.git</literallayout>
<para><?xxe-sn 2ckdfwgr1fk o?>Enter into the source directory and run the
following script to prepare building environment. Script will install the
required system packages as well as Coco and Clingo from sources:</para>
<remark><?xxe-sn 2ckdfwgr1fk p?>"Enter into source directory" - тут перед
directory явно нужен артикль. Гугл говорит, что определенный -
the</remark>
<important>
<?xxe-sn 2ckdfwgr1fk q?>
<para><?xxe-sn 2ckdfwgr1fk r?>Carefully inspect scripts before
run</para>
</important>
<para><?xxe-sn 2ckdfwgr1fk s?>On <emphasis role="bold"><?xxe-sn 2ckdfwgr1fk t?>OpenSuse
Leap 15</emphasis>:</para>
<literallayout><?xxe-sn 2ckdfwgr1fk u?>./installation/prepare-opensuse-leap15</literallayout>
<para><?xxe-sn 2ckdfwgr1fk v?>That was one time operation to prepare
environment. After that enter into <code><?xxe-sn 2ckdfwgr1fk w?>build</code>
directory and start actual tests building:</para>
<remark><?xxe-sn 2ckdfwgr1fk x?>"build directory": здесь ты все-таки
вначале указываешь имя объекта (build), и лишь потом родовое название
(directory)</remark>
<literallayout><?xxe-sn 2ckdfwgr1fk y?>cd build
make</literallayout>
<para><?xxe-sn 2ckdfwgr1fk z?>After successful build you can run xreate
tests:</para>
<literallayout><?xxe-sn 2ckdfwgr1fk 10?>cd ..
./build/tests/xreate-tests</literallayout>
<note>
<?xxe-sn 2ckdfwgr1fk 11?>
<para><?xxe-sn 2ckdfwgr1fk 12?>Please pay attention that the working
directory should be the repository root</para>
</note>
<para><?xxe-sn 2ckdfwgr1fk 13?>For consequent rebuilds after updates etc
invoke <code><?xxe-sn 2ckdfwgr1fk 14?>cmake</code> as follows:</para>
<literallayout><?xxe-sn 2ckdfwgr1fk 15?>#working dir build
cmake -DCMAKE_BUILD_TYPE=Debug \
-DBUILD_XREATE_TESTS=1 \
-DCOCO_EXECUTABLE=<FILE> \
-DCLINGO_PATH=<DIR> \
-DCOCO_FRAMES_PATH=../vendors/coco/generator/ \
-DCMAKE_CXX_COMPILER=g++ ../cpp
make</literallayout>
- <para><?xxe-sn 2ckdfwgr1fk 16?>Cmake's selected parameters:</para>
+ <para><?xxe-sn 2ckdfwgr1fk 16?><code><?xxe-sn 2coi7ojavb4 a?>cmake</code>'s
+ selected parameters:</para>
<itemizedlist>
<?xxe-sn 2ckdfwgr1fk 17?>
<listitem>
<?xxe-sn 2ckdfwgr1fk 18?>
<para><?xxe-sn 2ckdfwgr1fk 19?>BUILD_XREATE_TESTS Determines whether
to build tests</para>
</listitem>
<listitem>
<?xxe-sn 2ckdfwgr1fk 1a?>
<para><?xxe-sn 2ckdfwgr1fk 1b?>COCO_EXECUTABLE Full filename of Coco
executable</para>
</listitem>
<listitem>
<?xxe-sn 2ckdfwgr1fk 1c?>
<para><?xxe-sn 2ckdfwgr1fk 1d?>CLINGO_PATH Installed Clingo
directory</para>
<remark><?xxe-sn 2ckdfwgr1fk 1e?>"Directory of Clingo installation":
может, with Clingo installation? (это если речь идет о папке, где
хранятся инсталляционные файлы) Если наоборот, куда будет
устанавливаться - тогда Directory for installing Clingo. Оригинальный
вариант ("of Clingo installation") немного сбивает с толку.</remark>
</listitem>
</itemizedlist>
</section>
+
+ <section>
+ <?xxe-sn 2coi7ojavb4 1?>
+
+ <title condition="demo"><?xxe-sn 2coi7ojavb4 2?>Experimenting</title>
+
+ <para><?xxe-sn 2coi7ojavb4 3?>At this point the only executable produced
+ by <code><?xxe-sn 2coi7ojavb4 x?>make</code> is a collection of the unit
+ tests. There are many existing unit tests located in the <code><?xxe-sn 2coi7ojavb4 y?>cpp/tests</code>
+ to check correctness of various compilation aspects. Unit tests are
+ configured via the file <code><?xxe-sn 2coi7ojavb4 5?>config/default.json</code>
+ with the relevant settings located in the section <code><?xxe-sn 2coi7ojavb4 6?>tests</code>.
+ The section looks like this:</para>
+
+ <literallayout><?xxe-sn 2coi7ojavb4 b?>"tests": {
+ "template": "default",
+
+ "templates": {
+ "default": "*",
+
+ "documentation": "Modules.Doc_*:Modules_API.Doc_*",
+ "ast": "AST.*",
+ ...
+ }
+}</literallayout>
+
+ <para><?xxe-sn 2coi7ojavb4 c?>Key <code><?xxe-sn 2coi7ojavb4 d?>tests.template</code>
+ determines which group of unit tests should be executed, while section
+ <code><?xxe-sn 2coi7ojavb4 e?>test.templates</code> describes all
+ available groups. Note, that exact syntax of unit tests selection is
+ described in the Google Tests library documentation. By modifying this
+ configuration you can choose which tests you want to execute. </para>
+
+ <para><?xxe-sn 2coi7ojavb4 f?>In order to experiment with the compiler you
+ need to write your own unit-tests. There are several steps to complete to
+ add and run new unit tests:</para>
+
+ <itemizedlist>
+ <?xxe-sn 2coi7ojavb4 g?>
+
+ <listitem>
+ <?xxe-sn 2coi7ojavb4 h?>
+
+ <para><?xxe-sn 2coi7ojavb4 i?>Add new file to the <code><?xxe-sn 2coi7ojavb4 j?>cpp/tests</code>.</para>
+ </listitem>
+
+ <listitem>
+ <?xxe-sn 2coi7ojavb4 k?>
+
+ <para><?xxe-sn 2coi7ojavb4 l?>Register test by adding its filename to
+ the variable <code><?xxe-sn 2coi7ojavb4 10?>TEST_FILES</code> in the
+ <code><?xxe-sn 2coi7ojavb4 m?>test/CMakeLists.txt</code>.</para>
+ </listitem>
+
+ <listitem>
+ <?xxe-sn 2coi7ojavb4 n?>
+
+ <para><?xxe-sn 2coi7ojavb4 o?>Change <code><?xxe-sn 2coi7ojavb4 p?>config/default.json</code>
+ accordingly.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para><?xxe-sn 2coi7ojavb4 q?>Below is a bare bones example of a unit-test
+ as a starting point to get an idea:</para>
+
+ <literallayout><?xxe-sn 2coi7ojavb4 r?>name="tests/unit-test-example: Example.Example1", lines=15
+#include "xreatemanager.h" //main Xreate header
+#include "transcendlayer.h"
+#include <gtest/gtest.h>
+
+using namespace xreate;
+using namespace std;
+
+TEST(Example, Example1){
+ //(Optional) Your custom transcend rules if any
+ string rules =
+ R"SCRIPT(
+ bind_func(sum, entry).
+ )SCRIPT";
+
+ //Your custom program
+ string example =
+ R"CODE(
+ //Custom code
+
+ sum = function(a:: int, b:: int):: int
+ {
+ a + b
+ }
+ )CODE";
+
+ //Initialize compiler
+ unique_ptr<XreateManager> man(XreateManager::prepare(move(example)));
+
+ //Add transcend part:
+ man->transcend->addRawScript(move(rules));
+
+ //Define signature of your entry function:
+ typedef int (*ENTRYFN)(int, int);
+
+ //Compile the example and get a pointer to the entry function:
+ ENTRYFN yourEntryFn = (ENTRYFN) man->run();
+
+ //Now execute function and check the result
+ int resultActual = yourEntryFn(5, 7);
+ int resultExpected = 5 + 7;
+
+ ASSERT_EQ(resultExpected, resultActual);
+}</literallayout>
+
+ <para><?xxe-sn 2coi7ojavb4 u?>It outlines common unit test structure:
+ defines a program and optional transcend rules(in this case to designate
+ <code><?xxe-sn 2coi7ojavb4 w?>sum</code> as an entry function). Then the
+ program is compiled, executed and the result is checked against expected
+ value. </para>
+
+ <para><?xxe-sn 2coi7ojavb4 11?>Have a look at other existing unit tests
+ and see <link xlink:href="/api"><?xxe-sn 2coi7ojavb4 z?>Internal
+ API</link> to know more. </para>
+ </section>
</chapter>
Event Timeline
Log In to Comment