Skip to content

Commit

Permalink
Reorganized native tests a bit and re-enabled the ones for native dec…
Browse files Browse the repository at this point in the history
…larations without a header (ceylon/ceylon-spec#500 and ceylon/ceylon-spec#1286)
  • Loading branch information
quintesse committed May 6, 2015
1 parent 65b75f1 commit e972d3d
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.redhat.ceylon.compiler.java.test.nativecode;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import com.redhat.ceylon.compiler.java.test.CompilerError;
Expand All @@ -29,9 +28,13 @@
public class NativeTests extends CompilerTests {

private void testNative(String test) {
testNative("simple", test);
}

private void testNative(String dir, String test) {
boolean ok = false;
try {
compileAndRun("com.redhat.ceylon.compiler.java.test.nativecode.test" + test, test + ".ceylon");
compileAndRun("com.redhat.ceylon.compiler.java.test.nativecode." + dir + ".test" + test, dir + "/" + test + ".ceylon");
} catch (RuntimeException ex) {
assert(("ceylon.language.Exception \"" + test + "-JVM\"").equals(ex.getMessage()));
ok = true;
Expand All @@ -42,12 +45,16 @@ private void testNative(String test) {
}

private void testNativeErrors(String test, CompilerError... expectedErrors) {
assertErrors(test, expectedErrors);
testNativeErrors("simple", test, expectedErrors);
}

private void testNativeErrors(String dir, String test, CompilerError... expectedErrors) {
assertErrors(dir + "/" + test, expectedErrors);
}

// Methods

@Test @Ignore
@Test
public void testNativeMethodPrivate() {
testNative("NativeMethodPrivate");
}
Expand Down Expand Up @@ -76,12 +83,16 @@ public void testNativeMethodMismatch() {
new CompilerError(30, "native implementation must have the same return type as native abstraction: 'nativeMethodMismatch2' must have the type 'Anything'"),
new CompilerError(34, "native implementation must have the same return type as native abstraction: 'nativeMethodMismatch2' must have the type 'Anything'"),
new CompilerError(40, "member does not have the same number of parameters as native header: 'nativeMethodMismatch3'"),
new CompilerError(44, "type of parameter 's' of 'nativeMethodMismatch3' is different to type of corresponding parameter 'i' of native header 'nativeMethodMismatch3': 'String' is not exactly 'Integer'"));
new CompilerError(44, "type of parameter 's' of 'nativeMethodMismatch3' is different to type of corresponding parameter 'i' of native header 'nativeMethodMismatch3': 'String' is not exactly 'Integer'"),
new CompilerError(49, "function or value does not have a proper native backend implementation: 'nativeMethodMismatch4js'"),
new CompilerError(53, "function or value does not have a proper native backend implementation: 'nativeMethodMismatch4jvm'"),
new CompilerError(58, "function or value does not have a proper native backend implementation: 'nativeMethodMismatch4js'")
);
}

// Attributes

@Test @Ignore
@Test
public void testNativeAttributePrivate() {
testNative("NativeAttributePrivate");
}
Expand Down Expand Up @@ -127,7 +138,7 @@ public void testNativeAttributeMismatch() {

// Classes

@Test @Ignore
@Test
public void testNativeClassPrivate() {
testNative("NativeClassPrivate");
}
Expand Down Expand Up @@ -170,7 +181,10 @@ public void testNativeClassMismatch() {
new CompilerError(82, "native header for non-native declaration: 'NativeClassMismatch6'"),
new CompilerError(84, "native implementation for non-native header: 'NativeClassMismatch6'"),
new CompilerError(91, "formal member 'test1' of 'NativeClassMismatchSuper1' not implemented in class hierarchy"),
new CompilerError(92, "native backend must be the same as its container: 'test1' of 'NativeClassMismatch7'")
new CompilerError(92, "native backend must be the same as its container: 'test1' of 'NativeClassMismatch7'"),
new CompilerError(98, "type does not have a proper native backend implementation: 'NativeClassMismatch8js'"),
new CompilerError(104, "type does not have a proper native backend implementation: 'NativeClassMismatch8jvm'"),
new CompilerError(110, "type does not have a proper native backend implementation: 'NativeClassMismatch8js'")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,21 @@ native class NativeClassMismatch7() satisfies NativeClassMismatchSuper1 {
native("jvm") class NativeClassMismatch7() satisfies NativeClassMismatchSuper1 {
native("js") shared actual void test1(Integer i) {}
}


native("jvm") class NativeClassMismatch8jvm() satisfies NativeClassMismatchSuper1 {
native("jvm") shared actual void test1(Integer i) {
NativeClassMismatch8js().test2(i);
}
}

native("js") class NativeClassMismatch8js() satisfies NativeClassMismatchSuper2 {
native("js") shared actual void test2(Integer i) {
NativeClassMismatch8jvm().test1(i);
}
}

void nativeClassMismatch8() {
NativeClassMismatch8jvm().test1(0);
NativeClassMismatch8js().test2(0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ native("jvm") void nativeMethodMismatch3(Integer i, Boolean b) {
native("js") void nativeMethodMismatch3(String s) {
throw Exception("NativeMethodMismatch-JS");
}

native("jvm") void nativeMethodMismatch4jvm() {
nativeMethodMismatch4js();
}

native("js") void nativeMethodMismatch4js() {
nativeMethodMismatch4jvm();
}

void test() {
nativeMethodMismatch4jvm();
nativeMethodMismatch4js();
}

0 comments on commit e972d3d

Please sign in to comment.