summaryrefslogtreecommitdiff
path: root/chapter23
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-17 14:36:22 -0700
committerCliff Click <cliffc@acm.org>2026-09-17 14:36:22 -0700
commit0c99d74c85b937e5d566a7f2899d75025d9c54ea (patch)
tree9f4834d3fb1ec936fbea575d241f05a53c09336e /chapter23
parent410ee209ba1db89959f8e6be9cdaf2350e70fd27 (diff)
downloadSimple-0c99d74c85b937e5d566a7f2899d75025d9c54ea.tar.gz
Simple-0c99d74c85b937e5d566a7f2899d75025d9c54ea.zip
Get makefiles and fuzzer testing uniform across chapters
Diffstat (limited to 'chapter23')
-rw-r--r--chapter23/Makefile6
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/FuzzerWrap.java27
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java14
3 files changed, 38 insertions, 9 deletions
diff --git a/chapter23/Makefile b/chapter23/Makefile
index 6547a73a..deca5c76 100644
--- a/chapter23/Makefile
+++ b/chapter23/Makefile
@@ -89,7 +89,7 @@ $(CLZDIR)/main/.mtag: $(main_classes) $(main_javas)
@# This crap is really just "javac", but with a beautiful error message.
@# The very very long list of java files is suppressed and counted.
@# The required output "Note: blah blah deprecated blah" is suppressed.
- $(file > .argsM.txt , $(OODM))
+ $(file >.argsM.txt,$(OODM))
@if [ ! -z "$(OODM)" ] ; then \
echo "compiling main because " $< " and " `wc -w < .argsM.txt` " more files" ; \
if ! javac $(JAVAC_ARGS) -cp "$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(SRC) -d $(CLZDIR)/main $(OODM) >& .out.txt ; then \
@@ -111,7 +111,7 @@ $(main_classes): $(CLZDIR)/main/%class: $(SRC)/%java
OODT :=
$(CLZDIR)/test/.ttag: $(test_classes) $(test_javas) $(CLZDIR)/main/.mtag
@[ -d $(CLZDIR)/test ] || mkdir -p $(CLZDIR)/test
- $(file > .argsT.txt $(OODT))
+ $(file >.argsT.txt,$(OODT))
@if [ ! -z "$(OODT)" ] ; then \
echo "compiling test because " $< " and " `wc -w < .argsT.txt` " more files" ; \
if ! javac $(JAVAC_ARGS) -cp "$(CLZDIR)/test$(SEP)$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(TST) -d $(CLZDIR)/test $(OODT) >& .out.txt ; then \
@@ -177,4 +177,4 @@ lib/hamcrest-core-1.3.jar:
# Build emacs tags (part of a tasty emacs ide experience)
tags: $(main_javas) $(test_javas)
@rm -f TAGS
- @$(CTAGS) -e --recurse=yes --extras=+q --fields=+fksaiS $(SRC) $(TST)
+ @$(CTAGS) -e --recurse=yes --extra=+q --fields=+fksaiS $(SRC) $(TST)
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/chapter23/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index d67b2065..b022bec9 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/chapter23/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -7,15 +7,30 @@ import org.junit.Test;
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>
+ * Normal tests run chapter-local regression seeds. Open failures and exploratory
+ * fuzzing are opt-in (run directly in the IDE or temporarily remove Ignore).
+ * Seeds depend on this chapter's generator; do not copy them between chapters.
*/
public class FuzzerWrap {
+ private static final long[] REGRESSION_SEEDS = {
+ };
+
+ private static final long[] OPEN_FAILING_SEEDS = {
+ };
+
+ @Test public void fuzzPeepsRegression () { fuzzPeepsSeeds(REGRESSION_SEEDS); }
+ @Test @Ignore public void fuzzPeepsOpenFailures() { fuzzPeepsSeeds(OPEN_FAILING_SEEDS); }
+
+ private static void fuzzPeepsSeeds(long... seeds) {
+ var fuzzer = new Fuzzer();
+ for (long seed : seeds)
+ fuzzer.fuzzPeepsRegression(seed);
+ }
+
@Ignore
@Test
- public void fuzzPeeps() {
+ public void fuzzPeepsLarge() {
var fuzzer = new Fuzzer();
for (int i=0; i<1000000; i++)
fuzzer.fuzzPeeps(i);
@@ -23,8 +38,8 @@ public class FuzzerWrap {
}
- @Test
- public void fuzzPeepsSmall() {
+ @Test @Ignore
+ public void fuzzPeepsRandom() {
Random R = new Random(System.currentTimeMillis());
var fuzzer = new Fuzzer();
for (int i=0; i<100; i++)
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter23/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index 77e61b42..962202a6 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/chapter23/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -171,4 +171,18 @@ public class Fuzzer {
public boolean noExceptions() {
return exceptions.isEmpty();
}
+
+ /** Run a fixed chapter-local seed without reducing or swallowing failures. */
+ public void fuzzPeepsRegression(long seed) {
+ var rand = new Random(seed);
+ var sb = new StringBuilder();
+ var valid = new ScriptGenerator(rand, sb, true).genProgram();
+ try {
+ runCheck(sb.toString(), valid);
+ } catch (Throwable e) {
+ AssertionError ae = new AssertionError("Fuzzer regression seed failed: " + seed);
+ ae.initCause(e);
+ throw ae;
+ }
+ }
}