Skip to content

Commit 9f863f2

Browse files
authored
Merge pull request #17 from jonas/testing
Migrating tests to Scala
2 parents c0967a9 + d5f7adc commit 9f863f2

File tree

17 files changed

+293
-14
lines changed

17 files changed

+293
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
target
1+
target/

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ sudo: required
33
compiler: gcc
44

55
script:
6-
- docker-compose build ubuntu-16.04-llvm-$LLVM_VERSION
7-
- docker run --rm -ti scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION /usr/include/ctype.h -name ctype --
8-
- docker run --rm -ti --entrypoint /src/target/scalaBindgenTest scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION
6+
- docker-compose build $TEST_ENV
7+
- docker run --rm -ti scala-native-bindgen:$TEST_ENV /usr/include/ctype.h -name ctype --
8+
- docker-compose run --rm sbt-test
99

1010
matrix:
1111
include:
12-
- env: LLVM_VERSION=dev
13-
- env: LLVM_VERSION=6.0
14-
- env: LLVM_VERSION=5.0
12+
- env: TEST_ENV=ubuntu-16.04-llvm-dev
13+
- env: TEST_ENV=ubuntu-16.04-llvm-6.0
14+
- env: TEST_ENV=ubuntu-16.04-llvm-5.0

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ FROM ubuntu:$UBUNTU_VERSION
33

44
RUN set -x \
55
&& apt update \
6-
&& apt install -y curl build-essential \
6+
&& apt install -y apt-transport-https \
7+
&& echo "deb https://dl.bintray.com/sbt/debian /" > /etc/apt/sources.list.d/sbt.list \
8+
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823 \
9+
&& apt update \
10+
&& apt install -y curl build-essential openjdk-8-jdk-headless sbt \
711
&& rm -rf /var/lib/apt/lists/*
812

913
WORKDIR /cmake
@@ -20,7 +24,7 @@ ARG LLVM_DEB_COMPONENT=-$LLVM_VERSION
2024
RUN set -x \
2125
&& curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
2226
&& . /etc/lsb-release \
23-
&& echo "deb http://apt.llvm.org/$DISTRIB_CODENAME/ llvm-toolchain-$DISTRIB_CODENAME$LLVM_DEB_COMPONENT main" > /etc/apt/sources.list.d/llvm.list \
27+
&& echo "deb https://apt.llvm.org/$DISTRIB_CODENAME/ llvm-toolchain-$DISTRIB_CODENAME$LLVM_DEB_COMPONENT main" > /etc/apt/sources.list.d/llvm.list \
2428
&& apt update \
2529
&& apt install -y clang-$LLVM_VERSION libclang-$LLVM_VERSION-dev make \
2630
&& rm -rf /var/lib/apt/lists/*

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@ Running the previous command wild also yield warnings along with the translation
1616

1717
## Building
1818

19-
Building this tool requires LLVM and Clang. Ensure that `llvm-config` is in your path.
19+
Building this tool requires [CMake], [LLVM] and [Clang]. See the [Scala
20+
Native setup guide] for instructions on installing the dependencies.
2021

2122
```sh
22-
# Validate LLVM installation
23-
llvm-config --version --cmakedir --cxxflags --ldflags
24-
2523
mkdir -p target
2624
cd target
2725
cmake ..
2826
make
29-
./scalaBindgen /usr/include/ctype.h -name ctype
27+
./scalaBindgen /usr/include/ctype.h -name ctype --
28+
```
29+
30+
[CMake]: https://cmake.org/
31+
[LLVM]: https://llvm.org/
32+
[Clang]: https://clang.llvm.org/
33+
[Scala Native setup guide]: http://www.scala-native.org/en/latest/user/setup.html
34+
35+
## Testing
36+
37+
The tests assumes that the above instructions for building has been
38+
followed.
39+
40+
```sh
41+
cd tests
42+
sbt test
3043
```
3144

3245
## License

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ services:
2626
- UBUNTU_VERSION=16.04
2727
- LLVM_VERSION=5.0
2828

29+
sbt-test:
30+
image: scala-native-bindgen:${TEST_ENV}
31+
entrypoint:
32+
- sh
33+
- -c
34+
- |
35+
cd /src/tests
36+
sbt compile test
37+
volumes:
38+
- ${HOME}/.ivy2:/root/.ivy2
39+
- ${HOME}/.sbt:/root/.sbt

tests/build.sbt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
inThisBuild(
2+
Def.settings(
3+
organization := "org.scalanative.bindgen",
4+
version := "0.1-SNAPSHOT",
5+
scalaVersion := "2.11.12",
6+
scalacOptions ++= Seq(
7+
"-deprecation",
8+
"-unchecked",
9+
"-feature",
10+
"-encoding",
11+
"utf8"
12+
)
13+
))
14+
15+
val `scala-native-bindgen-tests` = project
16+
.in(file("."))
17+
.settings(
18+
fork in Test := true,
19+
javaOptions in Test += "-Dbindgen.path=" + file("../target/scalaBindgen"),
20+
watchSources += WatchSource(
21+
baseDirectory.value / "samples",
22+
"*.h" || "*.scala",
23+
NothingFilter
24+
),
25+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
26+
)
27+
28+
val samples = project
29+
.enablePlugins(ScalaNativePlugin)

tests/project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.1.6

tests/project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.7")

tests/samples/Function.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int no_args();
2+
int void_arg(void);
3+
void one_arg(int a);
4+
void *two_args(float a, int b);
5+
void anonymous_args(float, int);
6+
double variadic_args(double a, void* b, ...);

tests/samples/Function.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.scalanative._
2+
import scala.scalanative.native._
3+
import scala.scalanative.native.Nat._
4+
5+
@native.link("Function")
6+
@native.extern
7+
object Function {
8+
def no_args(): native.CInt = native.extern
9+
def void_arg(): native.CInt = native.extern
10+
def one_arg(a: native.CInt): Unit = native.extern
11+
def two_args(a: native.CFloat, b: native.CInt): native.Ptr[Byte] = native.extern
12+
def anonymous_args(anonymous0: native.CFloat, anonymous1: native.CInt): Unit = native.extern
13+
def variadic_args(a: native.CDouble, b: native.Ptr[Byte], varArgs: native.CVararg*): native.CDouble = native.extern
14+
}

0 commit comments

Comments
 (0)