Skip to content

Commit 681edc6

Browse files
committed
Split NativeTest into separate BytecodeEvaluableTest and NativeEvaluableTest
1 parent be2f832 commit 681edc6

File tree

3 files changed

+409
-405
lines changed

3 files changed

+409
-405
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.smoothbuild.cli.accept;
2+
3+
import static com.google.common.truth.Truth.assertThat;
4+
import static java.lang.String.format;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.smoothbuild.evaluator.testing.EvaluatorTestContext;
8+
import org.smoothbuild.virtualmachine.testing.func.bytecode.NonPublicMethod;
9+
import org.smoothbuild.virtualmachine.testing.func.bytecode.ReturnAbc;
10+
import org.smoothbuild.virtualmachine.testing.func.bytecode.ReturnIdFunc;
11+
12+
public class BytecodeEvaluableTest extends EvaluatorTestContext {
13+
@Test
14+
void func_call_can_be_evaluated() throws Exception {
15+
var userModule = format(
16+
"""
17+
@Bytecode("%s")
18+
A myId<A>(A a);
19+
result = myId(77);
20+
""",
21+
ReturnIdFunc.class.getCanonicalName());
22+
createUserModule(userModule, ReturnIdFunc.class);
23+
evaluate("result");
24+
assertThat(artifact()).isEqualTo(bInt(77));
25+
}
26+
27+
@Test
28+
void without_native_jar_file_causes_fatal() throws Exception {
29+
createUserModule(
30+
"""
31+
@Bytecode("MissingClass")
32+
String myFunc();
33+
result = myFunc();
34+
""");
35+
evaluate("result");
36+
assertThat(logs())
37+
.contains(userFatal(
38+
1,
39+
"Error loading native jar '{t-project}/module.jar'.\n"
40+
+ "Cannot read '{t-project}/module.jar'. "
41+
+ "File '{t-project}/module.jar' doesn't exist."));
42+
}
43+
44+
@Test
45+
void func_with_illegal_impl_causes_fatal() throws Exception {
46+
var userModule = format(
47+
"""
48+
@Bytecode("%s")
49+
Int brokenFunc();
50+
result = brokenFunc();
51+
""",
52+
NonPublicMethod.class.getCanonicalName());
53+
createUserModule(userModule, NonPublicMethod.class);
54+
evaluate("result");
55+
assertThat(logs())
56+
.containsExactly(userFatal(
57+
1,
58+
"Error loading bytecode for `brokenFunc`"
59+
+ " using provider specified as `" + NonPublicMethod.class.getCanonicalName()
60+
+ "`: Providing method is not public."));
61+
}
62+
63+
@Test
64+
void value_can_be_evaluated() throws Exception {
65+
var userModule = format(
66+
"""
67+
@Bytecode("%s")
68+
String result;
69+
""",
70+
ReturnAbc.class.getCanonicalName());
71+
createUserModule(userModule, ReturnAbc.class);
72+
evaluate("result");
73+
assertThat(artifact()).isEqualTo(bString("abc"));
74+
}
75+
76+
@Test
77+
void value_with_illegal_impl_causes_fatal() throws Exception {
78+
var userModule = format(
79+
"""
80+
@Bytecode("%s")
81+
Int result;
82+
""",
83+
NonPublicMethod.class.getCanonicalName());
84+
createUserModule(userModule, NonPublicMethod.class);
85+
evaluate("result");
86+
assertThat(logs())
87+
.containsExactly(userFatal(
88+
1,
89+
"Error loading bytecode for `result` using "
90+
+ "provider specified as `" + NonPublicMethod.class.getCanonicalName()
91+
+ "`: Providing method is not public."));
92+
}
93+
}

0 commit comments

Comments
 (0)