Skip to content

Commit

Permalink
refactor tests and run interpreter before transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
peq committed May 16, 2018
1 parent 9dee7fc commit b85d321
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 154 deletions.
15 changes: 15 additions & 0 deletions de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/UtilsIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@ public static String getMethodName(final int depth) {
return ste[depth + 2].getMethodName();
}

/**
* Get the method name of the calling method, ignoring the given current class
*
* @return method name
*/
public static String getMethodName(String currentClass) {
StackTraceElement[] ste = Thread.currentThread().getStackTrace();
for (int i = 2; i < ste.length; i++) {
if (!ste[i].getClassName().equals(currentClass)) {
return ste[i].getMethodName();
}
}
return "";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ public void ondestroy() {

@Test
public void recyling() {
testAssertOkLines(true,
test().executeProg(true)
.executeProgOnlyAfterTransforms()
.lines(
"package test",
" native testSuccess()",
" native println(string msg)",
Expand All @@ -267,7 +269,7 @@ public void recyling() {
" destroy cs[j]",
" for int k = 0 to 6000",
" cs[k] = new C()",
// " println(I2S(k) + \" --> \" +I2S(cs[k] castTo int))",
" println(I2S(k) + \" --> \" +I2S(cs[k] castTo int))",
" if cs[6000] castTo int <= 6001",
" testSuccess()",
"endpackage"
Expand Down Expand Up @@ -543,7 +545,9 @@ public void override_valid_trans_big() {

@Test(expectedExceptions = DebugPrintError.class)
public void NPE() {
testAssertOkLines(true,
test().executeProg()
.executeProgOnlyAfterTransforms()
.lines(
"package test",
" native testSuccess()",
" class A",
Expand All @@ -553,13 +557,14 @@ public void NPE() {
" A a = null",
" if a.foo() == 7",
" testSuccess()",
"endpackage"
);
"endpackage");
}

@Test(expectedExceptions = DebugPrintError.class)
public void destroyed() {
testAssertOkLines(true,
test().executeProg()
.executeProgOnlyAfterTransforms()
.lines(
"package test",
" native testSuccess()",
" class A",
Expand All @@ -570,8 +575,7 @@ public void destroyed() {
" destroy a",
" if a.foo() == 7",
" testSuccess()",
"endpackage"
);
"endpackage");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.testng.annotations.Test;

import java.util.function.Function;

public class ClosureTests extends WurstScriptTest {


Expand Down Expand Up @@ -548,7 +546,9 @@ public void skipInClosure_fail() {

@Test
public void testDispatch() {
testAssertOkLines(true,
test().executeProg(true)
.executeProgOnlyAfterTransforms()
.lines(
"package A",
" native testSuccess()",
" interface B",
Expand All @@ -559,7 +559,8 @@ public void testDispatch() {
" bar(() -> 0)",
" B b2 = () -> 0",
" if (b2 castTo int) == 1",
" testSuccess()");
" testSuccess()"
);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,15 @@ private void testJurstWithJass(boolean executeProg, boolean withStdLib, String j
"example.j", jass,
"test.jurst", jurst
);
testScript(Collections.emptyList(), inputs, "JurstJassTest", executeProg, withStdLib, false);
testScript(Collections.emptyList(), inputs, "JurstJassTest", executeProg, withStdLib, false, false);
}

private void testJurst(boolean executeProg, boolean withStdLib, String jurst) {
testScript("test.jurst", jurst, "JurstTest", executeProg, withStdLib);
test().executeProg(executeProg)
.executeProgOnlyAfterTransforms()
.withStdLib(withStdLib)
.withCu(compilationUnit("test.jurst", jurst))
.run();
}

}
Loading

0 comments on commit b85d321

Please sign in to comment.