-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from FalsePattern/test-update
Updated testing
- Loading branch information
Showing
10 changed files
with
211 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Java CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
- name: Build with Maven | ||
run: mvn --batch-mode --update-snapshots package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/test/java/com/falsepattern/jfunge/storage/TestInterpreter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package com.falsepattern.jfunge.storage; | ||
|
||
import com.falsepattern.jfunge.interpreter.Interpreter; | ||
import lombok.val; | ||
import lombok.var; | ||
import org.apache.commons.io.output.TeeOutputStream; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TestInterpreter { | ||
private static final Interpreter.FileIOSupplier fakeSupplier = new Interpreter.FileIOSupplier() { | ||
|
||
private final Map<String, byte[]> files = new HashMap<>(); | ||
|
||
@Override | ||
public byte[] readFile(String file) throws IOException { | ||
if (files.containsKey(file)) { | ||
val b = files.get(file); | ||
return Arrays.copyOf(b, b.length); | ||
} else { | ||
try (val s = TestInterpreter.class.getResourceAsStream("/" + file)) { | ||
if (s == null) { | ||
throw new FileNotFoundException("Could not find resource " + file); | ||
} | ||
val ret = new ByteArrayOutputStream(); | ||
val b = new byte[4096]; | ||
var r = 0; | ||
while ((r = s.read(b)) > 0) { | ||
ret.write(b, 0, r); | ||
} | ||
val bytes = ret.toByteArray(); | ||
files.put(file, bytes); | ||
return Arrays.copyOf(bytes, bytes.length); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean writeFile(String file, byte[] data) { | ||
files.put(file, Arrays.copyOf(data, data.length)); | ||
return true; | ||
} | ||
}; | ||
|
||
@SuppressWarnings("SameParameterValue") | ||
private static byte[] readProgram(String path) { | ||
val program = new ByteArrayOutputStream(); | ||
Assertions.assertDoesNotThrow(() -> { | ||
val reader = TestInterpreter.class.getResourceAsStream(path); | ||
Assertions.assertNotNull(reader); | ||
var read = 0; | ||
val b = new byte[4096]; | ||
while ((read = reader.read(b)) > 0) { | ||
program.write(b, 0, read); | ||
} | ||
}); | ||
return program.toByteArray(); | ||
} | ||
|
||
private static int interpret(String[] args, byte[] code, int iterLimit, InputStream input, OutputStream output) { | ||
return Assertions.assertDoesNotThrow(() -> Interpreter.executeProgram(false, args, code, iterLimit, input, output, fakeSupplier)); | ||
} | ||
|
||
private static InputStream nullStream() { | ||
return new ByteArrayInputStream(new byte[0]); | ||
} | ||
|
||
@Test | ||
public void testMycology() { | ||
val checkingOutput = new ByteArrayOutputStream(); | ||
val output = new TeeOutputStream(checkingOutput, System.out); | ||
val program = readProgram("/mycology.b98"); | ||
val returnCode = interpret(new String[]{"mycology.b98"}, program, 300000, nullStream(), output); | ||
val txt = checkingOutput.toString(); | ||
String currentlyActiveFingerprint = null; | ||
boolean fingerprintHadError = false; | ||
boolean good = true; | ||
for (val line: txt.split("\n")) { | ||
if (line.startsWith("Testing fingerprint ")) { | ||
int start = "Testing fingerprint ".length(); | ||
currentlyActiveFingerprint = line.substring(start, start + 4); | ||
fingerprintHadError = false; | ||
} else if (line.equals("About to test detailed () behaviour with two fingerprints.")) { | ||
//Fingerprint core checks are over, stop tracking. | ||
currentlyActiveFingerprint = null; | ||
fingerprintHadError = false; | ||
} | ||
if (line.startsWith("BAD")) { | ||
if (good) { | ||
System.err.println("Found BAD check(s) in Mycology! Interpreter is NOT standard-compliant."); | ||
good = false; | ||
} | ||
if (currentlyActiveFingerprint != null) { | ||
if (!fingerprintHadError) { | ||
System.err.println("Broken fingerprint: " + currentlyActiveFingerprint); | ||
fingerprintHadError = true; | ||
} | ||
} else { | ||
System.err.println("Not inside a fingerprint test, base language spec is broken. Fix urgently!"); | ||
} | ||
System.err.print(" "); | ||
System.err.println(line); | ||
} | ||
} | ||
Assertions.assertTrue(good); | ||
Assertions.assertEquals(15, returnCode); | ||
} | ||
|
||
@Test | ||
public void testSemicolonAtStart() { | ||
System.out.println("Testing edge case ;;.@"); | ||
val output = new ByteArrayOutputStream(); | ||
val returnCode = interpret(new String[0], ";;.@".getBytes(StandardCharsets.UTF_8), 50, nullStream(), output); | ||
val txt = output.toString(); | ||
Assertions.assertEquals("0 ", txt); | ||
Assertions.assertEquals(0, returnCode); | ||
} | ||
|
||
@Test | ||
public void testPutCharAtStart() { | ||
System.out.println("Testing edge case 'a,@"); | ||
val output = new ByteArrayOutputStream(); | ||
val returnCode = interpret(new String[0], "'a,@".getBytes(StandardCharsets.UTF_8), 50, nullStream(), output); | ||
val txt = output.toString(); | ||
Assertions.assertEquals("a", txt); | ||
Assertions.assertEquals(0, returnCode); | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
src/test/java/com/falsepattern/jfunge/storage/TestMycology.java
This file was deleted.
Oops, something went wrong.