Skip to content

Commit 1bbcf4d

Browse files
authored
Merge pull request #16 from jonas/separate-test-program
Move tests to a separate executable
2 parents ec32313 + c64dfd3 commit 1bbcf4d

File tree

4 files changed

+70
-60
lines changed

4 files changed

+70
-60
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ compiler: gcc
55
script:
66
- docker-compose build ubuntu-16.04-llvm-$LLVM_VERSION
77
- docker run --rm -ti scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION /usr/include/ctype.h -name ctype --
8-
- docker run --rm -ti scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION
8+
- docker run --rm -ti --entrypoint /src/target/scalaBindgenTest scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION
99

1010
matrix:
1111
include:

CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ add_definitions(${LLVM_DEFINITIONS})
1111

1212
add_compile_options(-fexceptions -std=c++11)
1313

14-
add_executable(scalaBindgen
15-
Main.cpp
14+
add_library(scalaNativeBindgen
15+
STATIC
1616
ScalaFrontend.h
1717
TreeVisitor.h
1818
TreeVisitor.cpp
@@ -23,12 +23,27 @@ add_executable(scalaBindgen
2323
HeaderManager.cpp
2424
CycleDetection.h
2525
Utils.h
26-
catch/catch.hpp
27-
SimpleTypeTests.cpp
26+
)
27+
28+
add_executable(scalaBindgen
29+
Main.cpp
2830
)
2931

3032
target_link_libraries(scalaBindgen
3133
PRIVATE
34+
scalaNativeBindgen
35+
clangFrontend
36+
clangTooling
37+
)
38+
39+
add_executable(scalaBindgenTest
40+
SimpleTypeTests.cpp
41+
catch/catch.hpp
42+
)
43+
44+
target_link_libraries(scalaBindgenTest
45+
PRIVATE
46+
scalaNativeBindgen
3247
clangFrontend
3348
clangTooling
3449
)

Main.cpp

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "ScalaFrontend.h"
22
#include "Utils.h"
33

4-
#define CATCH_CONFIG_RUNNER
5-
#include "catch/catch.hpp"
6-
74
#include <sys/types.h>
85

96
static llvm::cl::OptionCategory Category("Binding Generator");
@@ -15,68 +12,59 @@ static llvm::cl::opt<bool> PrintHeadersLocation ("location", llvm::cl::cat(Categ
1512

1613

1714
int main(int argc, char *argv[]) {
15+
clang::tooling::CommonOptionsParser op(argc, (const char**)argv, Category);
16+
clang::tooling::ClangTool Tool(op.getCompilations(), op.getSourcePathList());
1817

19-
if(argc <= 1 ){
18+
auto lib = LibName.getValue();
19+
if(lib == ""){
20+
llvm::errs() << "Error: Please specify the lib name using -name paramter\n";
21+
return -1;
22+
}
2023

21-
int result = Catch::Session().run( argc, argv );
22-
return result;
24+
auto stdhead = StdHeaders.getValue();
25+
if(stdhead != ""){
26+
headerMan.LoadConfig(stdhead);
27+
}
2328

24-
} else{
29+
declarations = "";
30+
enums = "";
31+
helpers = "";
32+
locations.clear();
2533

26-
clang::tooling::CommonOptionsParser op(argc, (const char**)argv, Category);
27-
clang::tooling::ClangTool Tool(op.getCompilations(), op.getSourcePathList());
34+
int result = Tool.run(clang::tooling::newFrontendActionFactory<ScalaFrontendAction>().get());
2835

29-
auto lib = LibName.getValue();
30-
if(lib == ""){
31-
llvm::errs() << "Error: Please specify the lib name using -name paramter\n";
32-
return -1;
33-
}
36+
auto printLoc = PrintHeadersLocation.getValue();
3437

35-
auto stdhead = StdHeaders.getValue();
36-
if(stdhead != ""){
37-
headerMan.LoadConfig(stdhead);
38+
if(printLoc){
39+
for(const auto& location: locations){
40+
llvm::outs() << location;
3841
}
3942

40-
declarations = "";
41-
enums = "";
42-
helpers = "";
43-
locations.clear();
44-
45-
int result = Tool.run(clang::tooling::newFrontendActionFactory<ScalaFrontendAction>().get());
46-
47-
auto printLoc = PrintHeadersLocation.getValue();
48-
49-
if(printLoc){
50-
for(const auto& location: locations){
51-
llvm::outs() << location;
52-
}
53-
54-
} else {
55-
if(declarations != "" || enums != "")
56-
llvm::outs() << "import scala.scalanative._\n"
57-
<< "import scala.scalanative.native.Nat._\n\n";
58-
59-
if(declarations != ""){
60-
llvm::outs() << "@native.link(\"" << lib << "\")\n"
61-
<< "@native.extern\n"
62-
<< "object " << lib << " {\n"
63-
<< declarations
64-
<< "}\n\n"
65-
<< "import " + lib + "._\n\n";
66-
}
43+
} else {
44+
if(declarations != "" || enums != "")
45+
llvm::outs() << "import scala.scalanative._\n"
46+
<< "import scala.scalanative.native.Nat._\n\n";
47+
48+
if(declarations != ""){
49+
llvm::outs() << "@native.link(\"" << lib << "\")\n"
50+
<< "@native.extern\n"
51+
<< "object " << lib << " {\n"
52+
<< declarations
53+
<< "}\n\n"
54+
<< "import " + lib + "._\n\n";
55+
}
6756

68-
if(enums != ""){
69-
llvm::outs() << "object " << lib << "Enums {\n"
70-
<< enums
71-
<< "}\n\n";
72-
}
57+
if(enums != ""){
58+
llvm::outs() << "object " << lib << "Enums {\n"
59+
<< enums
60+
<< "}\n\n";
61+
}
7362

74-
if(helpers != ""){
75-
llvm::outs() << "object " << lib << "Helpers {\n"
76-
<< helpers
77-
<< "}\n\n";
78-
}
63+
if(helpers != ""){
64+
llvm::outs() << "object " << lib << "Helpers {\n"
65+
<< helpers
66+
<< "}\n\n";
7967
}
80-
return result;
8168
}
69+
return result;
8270
}

SimpleTypeTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#include "ScalaFrontend.h"
22

33
#include "clang/Tooling/Tooling.h"
4+
5+
#define CATCH_CONFIG_RUNNER
46
#include "catch/catch.hpp"
57

68
#include <iostream>
79

10+
int main(int argc, char *argv[]) {
11+
int result = Catch::Session().run( argc, argv );
12+
return result;
13+
}
14+
815
std::string Translate(std::string code){
916
declarations = "";
1017
enums = "";

0 commit comments

Comments
 (0)