Skip to content

Commit

Permalink
Added tests for native modules (see ceylon/ceylon-spec#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
quintesse committed May 20, 2015
1 parent 60c7e3e commit d375e49
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ private void testNativeErrors(String dir, String test, CompilerError... expected
assertErrors(dir + "/" + test, expectedErrors);
}

private void testNativeModule(String dir) {
boolean ok = false;
try {
compile(dir + "/test.ceylon", dir + "/module.ceylon");
run("com.redhat.ceylon.compiler.java.test.nativecode." + dir + ".test", new ModuleWithArtifact("com.redhat.ceylon.compiler.java.test.nativecode." + dir, "1.0"));
} catch (RuntimeException ex) {
assert(("ceylon.language.Exception \"" + dir + "-JVM\"").equals(ex.getMessage()));
ok = true;
}
if (!ok) {
Assert.fail("Test terminated incorrectly");
}
}

private void testNativeModuleErrors(String dir, CompilerError... expectedErrors) {
assertErrors(new String[] {dir + "/test.ceylon", dir + "/module.ceylon"}, defaultOptions, null, expectedErrors);
}

// Methods

@Test
Expand Down Expand Up @@ -188,6 +206,29 @@ public void testNativeClassMismatch() {
);
}

// Modules

@Test
public void testNativeModule() {
testNativeModule("modok");
}

@Test
public void testNativeModuleMissing() {
testNativeModuleErrors("modmissing",
new CompilerError(2, "Missing backend argument for native annotation on module: com.redhat.ceylon.compiler.java.test.nativecode.modmissing")
);
}

@Test
public void testNativeModuleWrong() {
testNativeModuleErrors("modwrong",
new CompilerError(2, "Module not meant for this backend: com.redhat.ceylon.compiler.java.test.nativecode.modwrong")
);
}

// Misc

@Test
public void testNativeInvalidTypes() {
testNativeErrors("NativeInvalidTypes",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
native
module com.redhat.ceylon.compiler.java.test.nativecode.modmissing "1.0" {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shared void test() {
throw Exception("modmissing-JVM");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
native("jvm")
module com.redhat.ceylon.compiler.java.test.nativecode.modok "1.0" {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shared void test() {
throw Exception("modok-JVM");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
native("js")
module com.redhat.ceylon.compiler.java.test.nativecode.modwrong "1.0" {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shared void test() {
throw Exception("modmissing-JVM");
}

0 comments on commit d375e49

Please sign in to comment.