Skip to content

Commit a0b5c99

Browse files
Elena VolkovaGitHub Enterprise
authored andcommitted
RIC-1047: test include paths (#108)
* RIC-1047: Update TestUtils to use .h and .cpp files instead of .art * RIC-1047: New .h and .cpp files * Ignore RIC- folders for git * RIC-1047: Add using for std::cout, std::cerr and std::endl * include iostream in test header * Added include guards to prevent multiple inclusion of header * Updated cout, endl, added using chrono_literals * Fixed order of include paths
1 parent 6eb0672 commit a0b5c99

File tree

15 files changed

+78
-78
lines changed

15 files changed

+78
-78
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ art-comp-test/tests/**/*_target/*
99
art-comp-test/**/.vscode/art_build_settings.json
1010
art-comp-test/testLib_target/*
1111
art-comp-test/tests/*/logs/application.log
12-
art-samples/TcpRangeCounter/*/node_modules
12+
art-samples/TcpRangeCounter/*/node_modules
13+
RIC-*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdlib.h>
2+
#include "testLib.h"
3+
4+
void TestUtils::fail(const std::string& msg) {
5+
std::cerr << "TEST FAILED (" << msg << ")" << std::endl << std::flush;
6+
exit(1);
7+
}
8+
9+
void TestUtils::pass() {
10+
std::cout << "***PASS***" << std::endl << std::flush;
11+
//exit(0);
12+
}
13+
14+
void TestUtils::assert_(bool cond, const char* expr, const char * file, int line, const char* msg) {
15+
if (cond) {
16+
std::string okMessage = "OK: " + std::string(expr) + "\n";
17+
std::cout << okMessage;
18+
return;
19+
}
20+
21+
std::cerr << "ASSERTION FAILED (" << msg << ")" << std::endl << std::flush;
22+
}

art-comp-test/TestUtils/testLib.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef TEST_LIB_H
2+
#define TEST_LIB_H
3+
4+
#include <iostream>
5+
#include <string>
6+
7+
using std::cout;
8+
using std::cerr;
9+
using std::endl;
10+
11+
namespace TestUtils {
12+
13+
// Fail the test case with a message
14+
void fail(const std::string& msg);
15+
16+
// Pass the test case
17+
void pass();
18+
19+
// Assert on the condition being true. If not, the message (and condition expression and location of the assert)
20+
// will be printed and the test case will fail.
21+
void assert_(bool cond, const char* expr, const char * file, int line, const char* msg = "");
22+
#define assert(cond, ...) assert_(cond, #cond, __FILE__, __LINE__, ##__VA_ARGS__)
23+
24+
#define PASS() TestUtils::pass(); context()->abort()
25+
#define FAIL(msg) TestUtils::fail(msg);
26+
#define ASSERT(cond, msg) TestUtils::assert(cond, msg)
27+
}
28+
29+
#endif
Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +0,0 @@
1-
[[rt::decl]]
2-
`
3-
#include <string>
4-
#include <iostream>
5-
using namespace std;
6-
#include "../src/include/RTDiag.h"
7-
8-
namespace TestUtils {
9-
10-
// Read test options from the command line
11-
void getTestOptions(unsigned int& timeLimit);
12-
13-
// Fail the test case with a message
14-
void fail(const std::string& msg);
15-
16-
// Pass the test case
17-
void pass();
18-
19-
// Assert on the condition being true. If not, the message (and condition expression and location of the assert)
20-
// will be printed and the test case will fail.
21-
void assert_(bool cond, const char* expr, const char * file, int line, const char* msg = "");
22-
#define assert(cond, ...) assert_(cond, #cond, __FILE__, __LINE__, ##__VA_ARGS__)
23-
24-
#define PASS() TestUtils::pass(); context()->abort()
25-
#define FAIL(msg) TestUtils::fail(msg);
26-
#define ASSERT(cond, msg) TestUtils::assert(cond, msg)
27-
}
28-
`
29-
30-
[[rt::impl]]
31-
`
32-
#include <stdlib.h>
33-
34-
void TestUtils::getTestOptions(unsigned int& timeLimit) {
35-
int ac = RTMain::argCount();
36-
const char * const * av = RTMain::argStrings();
37-
38-
while( --ac > 0 ) {
39-
const char* arg = *++av;
40-
if( RTMemoryUtil::strcmp( arg, "-timeLimit=", 11 ) == 0 )
41-
timeLimit = RTMemoryUtil::atoi(*av + 11);
42-
}
43-
}
44-
45-
void TestUtils::fail(const std::string& msg) {
46-
std::cerr << "TEST FAILED (" << msg << ")" << std::endl << std::flush;
47-
exit(1);
48-
}
49-
50-
void TestUtils::pass() {
51-
std::cout << "***PASS***" << std::endl << std::flush;
52-
//exit(0);
53-
}
54-
55-
void TestUtils::assert_(bool cond, const char* expr, const char * file, int line, const char* msg) {
56-
if (cond) {
57-
std::string okMessage = "OK: " + std::string(expr) + "\n";
58-
std::cout << okMessage;
59-
return;
60-
}
61-
62-
std::cerr << "ASSERTION FAILED (" << msg << ")" << std::endl << std::flush;
63-
64-
RTDiag::failed_assertion(expr, file, line);
65-
}
66-
`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "testLib.h"

art-comp-test/TestUtils/testlib.tcjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//Transformation Configuration File
21
let tc = TCF.define(TCF.ART_TO_CPP);
32
tc.targetFolder = 'testLib_target';
43
tc.unitName = 'TestLibUnit';
4+
tc.cppCodeStandard = 'C++ 17';
55

66
// Uncomment to debug with Visual Studio
77
/*

art-comp-test/tc.code-workspace

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ "folders": [
2+
{
3+
"path": "TestUtils"
4+
},
5+
{
6+
"path": "tests/tc_include_paths"
7+
}
8+
]
9+
}

art-comp-test/tests/cpp_source_files/cpp_source_files.art

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ capsule Top {
99
initial -> State
1010
`
1111
bool isSimple = is_simple(17);
12-
std::cout << "is_simple(17) = " << isSimple << endl;
12+
cout << "is_simple(17) = " << isSimple << endl;
1313
ASSERT(is_simple(17) == true, "is_simple(17) function returned false");
1414
ASSERT(is_simple(15) == false, "is_simple(15) function returned true");
1515

art-comp-test/tests/dependency_injection_static/dependency_injection_static.art

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ protocol PROTO {
33
};
44

55
capsule Top {
6+
[[rt::impl_preface]]
7+
`
8+
#include "CapsuleFactory.h"
9+
`
610
part pinger : Pinger;
711
part logger : AbstractLogger;
812

art-comp-test/tests/dependency_injection_static/top.tcjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ tc.prerequisites = ["../../TestUtils/testlib.tcjs"];
44
tc.targetFolder = 'dependency_injection_static_target';
55
tc.commonPreface = `
66
#include <iostream>
7-
#include "testlib.art.h"
8-
#include "CapsuleFactory.h"
7+
#include "testLib.h"
98
`;
109
tc.capsuleFactory = '&CapsuleFactory::factory';

0 commit comments

Comments
 (0)