summaryrefslogtreecommitdiff
path: root/chapter10/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authorThalia Archibald <thalia@archibald.dev>2024-06-21 12:58:51 -0700
committerGitHub <noreply@github.com>2024-06-21 20:58:51 +0100
commitfd8442075faa603b3956d51d81486424624c5355 (patch)
tree029c1afb736ff0e350c2b032318e5fc376c7e1e4 /chapter10/src/test/java/com/seaofnodes
parente5f4f7b85fbb91a293a7d89d7b85adfbaeeb51f4 (diff)
downloadSimple-fd8442075faa603b3956d51d81486424624c5355.tar.gz
Simple-fd8442075faa603b3956d51d81486424624c5355.zip
Backport tests (#87)
* Fix unexpected number parse errors * Add chapter titles * Split test files by chapter * Backport rename Fuzzer08Test to FuzzerWrap * Replace graph build scripts with Makefile * Backport Chapter05Test.testRegress1 * Backport require space after 'return' * Backport check EOF after return statement
Diffstat (limited to 'chapter10/src/test/java/com/seaofnodes')
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter01Test.java54
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter02Test.java33
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter03Test.java4
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter04Test.java2
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter05Test.java14
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter06Test.java2
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter07Test.java5
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java1
-rw-r--r--chapter10/src/test/java/com/seaofnodes/simple/FuzzerWrap.java4
9 files changed, 57 insertions, 62 deletions
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter01Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter01Test.java
index 5abfc4cf..89882b2f 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter01Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter01Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
@@ -37,6 +35,15 @@ public class Chapter01Test {
assertEquals(TypeInteger.constant(0),con._type);
}
+ @Test
+ public void testBad1() {
+ try {
+ new Parser("ret").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Undefined name 'ret'",e.getMessage());
+ }
+ }
@Test
public void testBad2() {
@@ -47,4 +54,47 @@ public class Chapter01Test {
assertEquals("Syntax error: integer values cannot start with '0'",e.getMessage());
}
}
+
+ @Test
+ public void testNotBad3() {
+ // this test used to fail in chapter 1
+ assertEquals("return 12;", new Parser("return --12;").parse().print());
+ }
+
+ @Test
+ public void testBad4() {
+ try {
+ new Parser("return 100").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Syntax error, expected ;: ",e.getMessage());
+ }
+ }
+
+ @Test
+ public void testNotBad5() {
+ // this test used to fail in chapter 1
+ assertEquals("return -100;", new Parser("return -100;").parse().print());
+ }
+
+ @Test
+ public void testBad6() {
+ try {
+ new Parser("return100").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Undefined name 'return100'",e.getMessage());
+ }
+ }
+
+ @Test
+ public void testBad7() {
+ try {
+ new Parser("return 1;}").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Syntax error, unexpected }",e.getMessage());
+ }
+ }
+
}
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter02Test.java
index 107225ae..2deba460 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter02Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter02Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
@@ -65,35 +63,4 @@ public class Chapter02Test {
System.out.println(gv.generateDotOutput(parser));
}
- @Test
- public void testBad1() {
- try {
- new Parser("ret").parse();
- fail();
- } catch( RuntimeException e ) {
- assertEquals("Undefined name 'ret'",e.getMessage());
- }
- }
- @Test
- public void testNotBad3() {
- // this test used to fail in chapter 1
- assertEquals("return 12;", new Parser("return --12;").parse().print());
- }
-
- @Test
- public void testBad4() {
- try {
- new Parser("return 100").parse();
- fail();
- } catch( RuntimeException e ) {
- assertEquals("Syntax error, expected ;: ",e.getMessage());
- }
- }
-
- @Test
- public void testNotBad5() {
- // this test used to fail in chapter 1
- assertEquals("return -100;", new Parser("return -100;").parse().print());
- }
-
}
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter03Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter03Test.java
index 6bcfcc4b..407fbe48 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter03Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter03Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
@@ -58,7 +56,7 @@ public class Chapter03Test {
}
@Test
- public void testBad6() {
+ public void testBad1() {
try {
new Parser("int a=1; int b=2; int c=0; { int b=3; c=a+b;").parse();
fail();
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter04Test.java
index 5a024e77..cde23324 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter04Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter04Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index e82aa7da..44fff0c0 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
@@ -203,7 +201,7 @@ return a;""");
}
@Test
- public void testKeyword3() {
+ public void testKeyword3() {
try {
new Parser("int a=1; ififif(arg)inta=2;return a;").parse();
fail();
@@ -212,14 +210,4 @@ return a;""");
}
}
- @Test
- public void testBad7() {
- try {
- new Parser("return 1;}").parse();
- fail();
- } catch( RuntimeException e ) {
- assertEquals("Syntax error, unexpected }",e.getMessage());
- }
- }
-
}
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index 6c24992c..d30bd43d 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter06Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter07Test.java
index 29d16f32..a5cddb68 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter07Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter07Test.java
@@ -2,15 +2,12 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
public class Chapter07Test {
-
@Test
public void testExample() {
Parser parser = new Parser(
@@ -47,7 +44,6 @@ return a;
@Test
public void testWhileNested() {
Parser parser = new Parser(
-
"""
int sum = 0;
int i = 0;
@@ -240,4 +236,5 @@ return a;
assertEquals("return Phi(Loop8,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof ProjNode);
}
+
}
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index f7388ff9..2e1ae1aa 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -3,7 +3,6 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.Node;
import com.seaofnodes.simple.node.StopNode;
import com.seaofnodes.simple.type.*;
-import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/chapter10/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index 699711fc..bb3bec1c 100644
--- a/chapter10/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/chapter10/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -10,12 +10,12 @@ import static org.junit.Assert.assertTrue;
/**
* To use the fuzzer run the <code>fuzzPeeps</code> methods.
* This can be done from IntelliJ Gui or remove the `@Ignore` annotation and start the test case from the command line
- * via <code>mvn clean test -Dtest=com.seaofnodes.simple.Fuzzer08Test#fuzzPeeps</code>
+ * via <code>mvn clean test -Dtest=com.seaofnodes.simple.FuzzerWrap#fuzzPeeps</code>
*/
public class FuzzerWrap {
- @Ignore
@Test
+ @Ignore
public void fuzzPeeps() {
var fuzzer = new Fuzzer();
for (int i=0; i<1000000; i++)