diff --git a/.travis.yml b/.travis.yml index 51c03ea..6821d52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,22 +9,4 @@ cache: install: - ./gradlew clean build script: - - ./compile.sh tests/bracket-access.lj && ./test.sh - - ./compile.sh tests/comp/3np1for.lj && ./test.sh - - ./compile.sh tests/comp/3np1while.lj && ./test.sh - - ./compile.sh tests/comp/different.lj && ./test.sh - - ./compile.sh tests/comp/oddgnome.lj && ./test.sh - - ./compile.sh tests/collections.lj && ./test.sh - - ./compile.sh tests/demo.lj && ./test.sh - - ./compile.sh tests/dog.lj && ./test.sh - - ./compile.sh tests/eqtests.lj && ./test.sh - - ./compile.sh tests/fact.lj && ./test.sh - - ./compile.sh tests/forloop.lj && ./test.sh - - ./compile.sh tests/format.lj && ./test.sh - - ./compile.sh tests/fp.lj && ./test.sh - - ./compile.sh tests/oop.lj && ./test.sh - - ./compile.sh tests/precedence.lj && ./test.sh - - ./compile.sh tests/quicksort.lj && ./test.sh - - ./compile.sh tests/shadow.lj && ./test.sh - - ./compile.sh tests/type-inference.lj && ./test.sh - - ./compile.sh tests/unit-test.lj && ./test.sh + - ./dotests.sh -r tests/ diff --git a/README.md b/README.md index dad7151..4ccc642 100644 --- a/README.md +++ b/README.md @@ -18,69 +18,31 @@ Gradle wrapper so installing Gradle is not necessary. ``` ./gradlew build ```` -### Compiling a Less-Java Program - -A script is provided to compile any Less-Java program, and there are several -examples in the `tests/` directory. Compiling is fairly straightforward. +### Compiling and Running a Less-Java Program +A script is provided to compile, run, and test any Less-Java program with a single command. ``` -./compile.sh +./lj ```` For example, ``` -./compile.sh tests/fact.lj -``` -## Running - -It is possible to just run the most recently compiled program, or run a specific -previously compiled Less-Java program. - -### Running A Less-Java Program - -Ensure that the program you wish to run has already been compiled following the -instructions above. To run the most recently compiled or ran program, simply type: - -``` -./run.sh -``` - -To run a specific Less-Java program, use the name of the file you compiled. The -extension is optional. For example: - -``` -./run.sh fact.lj +./lj tests/fact.lj ``` You will need to make sure that your program has a `main()` method if you want to -run it. If it does not have a `main()` method, you will receive an error similar +run it. If it does not have a `main()` method, you will receive a warning similar to the following. ``` -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application -``` - -You can also compile and run a Less-Java program with a single instruction using the -go script. It works the same way as compilation: - -``` -./go.sh tests/fact.lj +Warning: This program does not contain a main() function and will not be run ``` +The program will still be compiled and tested correctly even without a main() method, but no program output +will be released. ##Testing -### Running Tests From A File - -Ensure that the file you wish to run the test from has been compiled following the -instructions above. Then simply run: - -``` -./test.sh -``` - ### Running All Tests It is possible to run all the tests in the `tests/` directory and to set the diff --git a/build.gradle b/build.gradle index 959268a..0e23916 100644 --- a/build.gradle +++ b/build.gradle @@ -66,6 +66,20 @@ task fatJar(type:Jar) { } baseName = 'lj-all' from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + from files(project('ljwrappers').sourceSets.main.runtimeClasspath) + with jar +} + +task ui(type:Jar) { + group 'LessJava' + description 'Assemble UI JAR' + + manifest { + attributes 'Main-Class': 'com.github.lessjava.LJUI' + } + baseName = 'lj-ui' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + from files(project('ljwrappers').sourceSets.main.runtimeClasspath) with jar } diff --git a/distribution/.gitignore b/distribution/.gitignore new file mode 100644 index 0000000..d392f0e --- /dev/null +++ b/distribution/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/distribution/compile.sh b/distribution/compile.sh deleted file mode 100755 index 197f1ec..0000000 --- a/distribution/compile.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -java -jar lj.jar $1 diff --git a/distribution/hello.lj b/distribution/hello.lj new file mode 120000 index 0000000..ad7e9fb --- /dev/null +++ b/distribution/hello.lj @@ -0,0 +1 @@ +../tests/io/hello-world.lj \ No newline at end of file diff --git a/compile.sh b/distribution/lj similarity index 75% rename from compile.sh rename to distribution/lj index 45eda6f..784c257 100755 --- a/compile.sh +++ b/distribution/lj @@ -1,6 +1,5 @@ #!/usr/bin/env bash - -GRADLE_WRAPPER="./gradlew" +# vim: set filetype=bash help() { echo "Usage: $0 [options] file" @@ -8,7 +7,6 @@ help() { echo " Options:" echo " -h Print this help message and exit" echo " -t Print type changes found by type inference" - echo " -v Print output from Gradle" } args="run" @@ -22,9 +20,6 @@ while getopts :thv flag; do t) args="${args} -PprintTypeChanges" ;; - v) - verbose=true - ;; \?) echo "Unrecognized option $OPTARG" 1>&2 echo @@ -46,6 +41,10 @@ if [ $# == 0 ]; then exit fi -args="${args} -Ptestfile=${1}" -"$GRADLE_WRAPPER" $args +args="${args} ${1}" +java -jar lj.jar ${args} +base=$(basename $1) +upbase="$(tr '[:lower:]' '[:upper:]' <<< ${base:0:1})${base:1}" +name="LJ${upbase%.*}" +java -cp "generated:lj.jar" $name exit diff --git a/distribution/lj.jar b/distribution/lj.jar deleted file mode 100644 index c19b1ee..0000000 Binary files a/distribution/lj.jar and /dev/null differ diff --git a/distribution/lj.zip b/distribution/lj.zip deleted file mode 100644 index 7ffdb60..0000000 Binary files a/distribution/lj.zip and /dev/null differ diff --git a/distribution/run.sh b/distribution/run.sh deleted file mode 100755 index 729d8ff..0000000 --- a/distribution/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java -cp generated Main diff --git a/distribution/test.sh b/distribution/test.sh deleted file mode 100755 index a780da2..0000000 --- a/distribution/test.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -printf "Compiling...\n" -if javac -cp .:lj.jar generated/Main.java; then - printf "Testing...\n" - java -cp .:generated:lj.jar org.junit.runner.JUnitCore Main -fi - diff --git a/distro.sh b/distro.sh index 9786bea..ba7d076 100755 --- a/distro.sh +++ b/distro.sh @@ -2,5 +2,12 @@ GRADLE_WRAPPER="./gradlew" +"$GRADLE_WRAPPER" clean + "$GRADLE_WRAPPER" fatJar -cp build/libs/*-all.jar distribution/lj.jar +cp build/libs/lj-all.jar distribution/lj.jar +cp libs/*.jar distribution/ + +"$GRADLE_WRAPPER" ui +cp build/libs/lj-ui.jar distribution/lj-ui.jar + diff --git a/dotests.sh b/dotests.sh index e94c999..14f39ce 100755 --- a/dotests.sh +++ b/dotests.sh @@ -11,11 +11,6 @@ help() { echo " If -s option not present, LJ file output will be compared to the previous expected output" } -# Takes the name of a file. If the input file is a LJ file, compile and run it. -# If the -s option is used, copy the outputs to the expected outputs file. -# Otherwise, show a diff between the expected and actual output. -# If the input file is a directory and the -r option is given, call test on the -# directory's contents test() { local file=${1%"/"} if [ -f $file ] && [[ $file =~ .*\.lj ]]; then @@ -25,64 +20,40 @@ test() { outdir=$parent/outputs base=$outdir/$name mkdir -p $outdir - echo "Compiling $file" - ./compile.sh $file 2>&1 | grep -wvi time > $base\_compile.out - echo "Done compiling" - echo - if [ -n "$(grep "main(" $file)" ]; then - echo "Running $file" - if [ -e "$parent/$name.in" ]; then - ./run.sh < "$parent/$name.in" 2>&1 | tee $base\_run.out - else - ./run.sh 2>&1 | tee $base\_run.out - fi - echo "Done running" - echo + echo "***************************************" + echo "Compiling, Running, and Testing $file" + if [ -e "$parent/$name.in" ]; then + ./lj $file < "$parent/$name.in" 2>&1 > $base.out + else + ./lj $file 2>&1 | grep -wvi time > $base.out fi - echo "Running tests for $file" - ./test.sh 2>&1 | grep -wvi time > $base\_test.out - echo "Done testing" + echo "Finished" echo if $set_expected; then - cp $base\_compile.out $base\_compile.exp - cp $base\_run.out $base\_run.exp - cp $base\_test.out $base\_test.exp + cp $base.out $base.exp + echo "Setting the expected output of $file to this actual output." + echo else - touch $base\_compile.exp - touch $base\_run.exp - touch $base\_test.exp - diff -uB $base\_compile.out $base\_compile.exp > $base\_compile.diff - if [ -s $base\_compile.diff ]; then - ((changes_found += 1)) - echo "Changes detected in compile output; use -s option to set expected output" + #touch $base.out + diff -uB $base.out $base.exp > $base.diff + if [ -s $base.diff ]; then + echo "Differences detected in actual output; use -s option to set the expected output." echo - cat $base\_compile.diff + cat $base.diff echo - fi - if [ -s "$(grep "main(" $file)" ]; then - diff -uB $base\_run.out $base\_run.exp > $base\_run.diff - if [ -s $base\_run.diff ]; then - ((changes_found += 1)) - echo "Changes detected in run output; use -s option to set expected output" - echo - cat $base\_run.diff - echo - fi - fi - diff -uB $base\_test.out $base\_test.exp > $base\_test.diff - if [ -s $base\_test.diff ]; then - ((changes_found += 1)) - echo "Changes detected in test output; use -s option to set expected output" - echo - cat $base\_test.diff + exit 1 + else + echo "No differences detected between expected and actual output." echo fi fi elif [ -d $file ] && $recursive; then for sub in $(ls $file); do - test $file/$sub + if [ ! "$(basename $file)" == "failing" ]; then + test $file/$sub + fi done - fi + fi } help_flag=false @@ -105,7 +76,7 @@ while getopts :hrs flag; do echo "Unexpected flag $OPTARG" 1>&2 echo help - exit + exit 1 ;; esac done @@ -121,17 +92,9 @@ if [ $# == 0 ]; then echo "Expecting at least one file" 1>&2 echo help - exit + exit 1 fi -changes_found=0 - -# For each input file f: for f in $@; do test $f done - -# Show how many changes were detected -if [ $set_expected == false ]; then - echo "Detected $changes_found changed outputs" -fi diff --git a/lj b/lj index 2dd4efe..f89a274 100755 --- a/lj +++ b/lj @@ -49,8 +49,37 @@ fi args="${args} -Ptestfile=${1}" "$GRADLE_WRAPPER" $args + +# If the less-java file contains the string "main()", attempt to run it. +# Otherwise, release a warning and continue +parent=$(dirname $1) base=$(basename $1) -upbase="$(tr '[:lower:]' '[:upper:]' <<< ${base:0:1})${base:1}" -name="LJ${upbase%.*}" -java -cp generated $name -exit +name=${base%.*} +count=$(grep -c "main()" "$1") +if [ "$count" -gt "0" ]; +then + if [ -e "$parent/$name.in" ]; + then + java -cp generated Main < "$parent/$name.in" + else + java -cp generated Main + fi +else + echo "Warning: This program does not contain a main() function and will not be run" +fi + +# --class-path allows specifying where JUnit should look for tests +# --include-classname allows the name to be anything +# --disable-banner disables the banner asking contributing to JUnit +# --scan-class-path checks the full classpath for tests +# Get the output but do not print it yet +test_output="$(java -jar libs/junit-platform-console-standalone-1.4.2.jar --class-path ".:generated" --include-classname='.*' --disable-banner --scan-class-path)" +# Preserve the exit code of the tests +test_status="$?" + +# The grep -v filter removes lines that are unnecessary or potentially +# confusing to an end user. +echo "$test_output" | grep -v -e '\[.*containers.*\]' -e 'JUnit Vintage' -e 'Test run finished after' + +# Ensure the exit code from the tests is the exit code of the script +exit "$test_status" diff --git a/run.sh b/run.sh deleted file mode 100755 index 96f4d0a..0000000 --- a/run.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -help() { - echo "Usage: $0 [file]" - echo "If no file is specified, the most recently compiled program will be run" -} - - -name="" -if [ $# == 0 ]; -then - cd ./generated/ - recent=$(ls -t | head -n1) - name=${recent%.*} - cd .. -else - base=$(basename $1) - upbase="$(tr '[:lower:]' '[:upper:]' <<< ${base:0:1})${base:1}" - name="LJ${upbase%.*}" -fi - -java -cp generated $name -exit diff --git a/src/main/java/com/github/lessjava/LJCompiler.java b/src/main/java/com/github/lessjava/LJCompiler.java index c6a8cfd..a3640ed 100644 --- a/src/main/java/com/github/lessjava/LJCompiler.java +++ b/src/main/java/com/github/lessjava/LJCompiler.java @@ -15,6 +15,7 @@ import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; +import com.github.lessjava.visitor.impl.LJCoerceIntsToDoubles; import org.antlr.v4.runtime.ANTLRFileStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.tree.ParseTree; @@ -28,7 +29,6 @@ import org.junit.platform.launcher.listeners.TestExecutionSummary; import static org.junit.platform.engine.discovery.DiscoverySelectors.*; -import static org.junit.platform.engine.discovery.ClassNameFilter.*; import com.github.lessjava.generated.LJLexer; import com.github.lessjava.generated.LJParser; @@ -78,10 +78,11 @@ public static void main(String[] args) throws IOException { BuildSymbolTables buildSymbolTables = new BuildSymbolTables(); LJASTInferTypes inferTypes = new LJASTInferTypes(); // PrintDebugTree printTree = new PrintDebugTree(); - LJGenerateJava generateJava = new LJGenerateJava(fileName); + LJGenerateJava generateJava = new LJGenerateJava(); LJASTCheckTypesHaveChanged checkTypesHaveChanged = new LJASTCheckTypesHaveChanged(); LJInstantiateFunctions instantiateFunctions = new LJInstantiateFunctions(); LJASTInferConstructors inferConstructors = new LJASTInferConstructors(); + LJCoerceIntsToDoubles coerceIntsToDoubles = new LJCoerceIntsToDoubles(); // ANTLR Parsing ParseTree parseTree = parser.program(); @@ -118,6 +119,9 @@ public static void main(String[] args) throws IOException { } } + // If we decide to stop coercing ints to doubles, remove this line and associated classes + program.traverse(coerceIntsToDoubles); + // TODO: Determine if necessary // program.traverse(new LJUnifyVariables()); @@ -178,7 +182,7 @@ private static void runTests(Class test) { summary.printTo(new PrintWriter(System.out)); } - private static class JCompiler { + public static class JCompiler { private static final JavaCompiler COMPILER = ToolProvider.getSystemJavaCompiler(); private static final StandardJavaFileManager FM = COMPILER.getStandardFileManager(null, null, null); private static final List OPTIONS = new ArrayList<>( diff --git a/src/main/java/com/github/lessjava/LJUI.java b/src/main/java/com/github/lessjava/LJUI.java new file mode 100644 index 0000000..bb64ccd --- /dev/null +++ b/src/main/java/com/github/lessjava/LJUI.java @@ -0,0 +1,273 @@ +package com.github.lessjava; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JButton; +import javax.swing.JToolBar; +import javax.swing.JSplitPane; +import javax.swing.JScrollPane; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.io.File; + +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ParseTreeWalker; + +import com.github.lessjava.generated.LJLexer; +import com.github.lessjava.generated.LJParser; +import com.github.lessjava.types.ast.ASTProgram; +import com.github.lessjava.types.ast.ASTClass; +import com.github.lessjava.types.ast.ASTClassBlock; +import com.github.lessjava.visitor.impl.BuildParentLinks; +import com.github.lessjava.visitor.impl.BuildSymbolTables; +import com.github.lessjava.visitor.impl.PrintDebugTree; +import com.github.lessjava.visitor.impl.LJASTBuildClassLinks; +import com.github.lessjava.visitor.impl.LJASTCheckTypesHaveChanged; +import com.github.lessjava.visitor.impl.LJASTConverter; +import com.github.lessjava.visitor.impl.LJASTInferConstructors; +import com.github.lessjava.visitor.impl.LJASTInferTypes; +import com.github.lessjava.visitor.impl.LJAssignTestVariables; +import com.github.lessjava.visitor.impl.LJGenerateJava; +import com.github.lessjava.visitor.impl.LJInstantiateFunctions; +import com.github.lessjava.visitor.impl.LJStaticAnalysis; +import com.github.lessjava.visitor.impl.StaticAnalysis; + +public class LJUI extends JFrame +{ + public static void main(String args[]) + { + (new LJUI()).setVisible(true); + } + + public LJUI() + { + // main text fields in a split pane + JTextArea editField = new JTextArea(); + editField.setText("main() {\n println(\"Hello, world!\")\n}\n" + + "test 1+2 == 3\n"); + editField.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 13)); + JTextArea outputField = new JTextArea(); + editField.setFont(new Font(Font.MONOSPACED, Font.BOLD, 13)); + JSplitPane splitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, + new JScrollPane(editField), new JScrollPane(outputField)); + splitPanel.setResizeWeight(0.33); + + // toolbar + JButton testButton = new JButton(); + testButton.setLabel("Test"); + testButton.setToolTipText("Run tests"); + testButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) + { outputField.setText(compile(editField.getText()) + test()); } + }); + JButton runButton = new JButton(); + runButton.setLabel("Run"); + runButton.setToolTipText("Run program"); + runButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) + { outputField.setText(compile(editField.getText()) + run()); } + }); + JToolBar toolbar = new JToolBar(); + toolbar.add(testButton); + toolbar.add(runButton); + + // top-level panel + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + mainPanel.add(toolbar, BorderLayout.NORTH); + mainPanel.add(splitPanel, BorderLayout.CENTER); + add(mainPanel); + pack(); + + // main window + setTitle("Less-Java"); + setSize(500,600); + setLocationRelativeTo(null); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + private void deleteFile(String path) + { + File f = new File(path); + if (f.isDirectory()) { + String[] children = f.list(); + if (children == null) { + // empty folder; just delete it + f.delete(); + } else { + // non-empty folder; delete all children first + for (String c : children) { + deleteFile(f.getAbsolutePath() + File.separator + c); + } + } + } + f.delete(); + } + + public String compile(String code) + { + // remove any old generated files + deleteFile("generated"); + new File("generated").mkdir(); + + // add newline to avoid EOL/EOF issues w/ ANTLR: + // https://www.antlr3.org/pipermail/antlr-interest/2011-January/040642.html + code += "\n"; + + // lexing and parsing (TODO: report errors in UI) + LJLexer lexer = new LJLexer(new ANTLRInputStream(code)); + LJParser parser = new LJParser(new CommonTokenStream(lexer)); + ParseTree parseTree = parser.program(); + if (parser.getNumberOfSyntaxErrors() != 0) { + return "Syntax error"; + } + + // conversion to AST + ParseTreeWalker walker = new ParseTreeWalker(); + LJASTConverter converter = new LJASTConverter(); + walker.walk(converter, parseTree); + ASTProgram program = converter.getAST(); + + // visitors + BuildParentLinks buildParentLinks = new BuildParentLinks(); + BuildSymbolTables buildSymbolTables = new BuildSymbolTables(); + LJInstantiateFunctions instantiateFunctions = new LJInstantiateFunctions(); + LJASTInferTypes inferTypes = new LJASTInferTypes(); + LJASTInferConstructors inferConstructors = new LJASTInferConstructors(); + LJASTCheckTypesHaveChanged checkTypesHaveChanged = new LJASTCheckTypesHaveChanged(); + + // reset static analysis (TODO: use fewer static data structures to + // avoid having to do this) + StaticAnalysis.resetErrors(); + BuildSymbolTables.nodeSymbolTableMap.clear(); + LJASTBuildClassLinks.nameClassMap.clear(); + LJASTBuildClassLinks.nameClassMap.put("Object",null); + LJASTBuildClassLinks.nameClassMap.put("String", null); + LJASTBuildClassLinks.nameClassMap.put("Integer", null); + LJASTBuildClassLinks.nameClassMap.put("Double", null); + LJASTBuildClassLinks.nameClassMap.put("Boolean", null); + LJASTBuildClassLinks.nameClassMap.put("Char", null); + LJASTBuildClassLinks.nameClassMap.put("LJList", null); + LJASTBuildClassLinks.nameClassMap.put("LJSet", null); + LJASTBuildClassLinks.nameClassMap.put("LJMap", null); + ASTClass.nameClassMap.clear(); + ASTClassBlock.nameAttributeMap.clear(); + StaticAnalysis.collectErrors = true; + + // initial processing + program.traverse(buildParentLinks); + program.traverse(new LJASTBuildClassLinks()); + if(!StaticAnalysis.getErrors().isEmpty()) { + return StaticAnalysis.getErrorString(); + } + program.traverse(new LJASTInferConstructors()); + program.traverse(buildSymbolTables); + + // iterative type inference + do { + program.traverse(buildParentLinks); + StaticAnalysis.resetErrors(); + program.traverse(buildSymbolTables); + program.traverse(instantiateFunctions); + program.traverse(inferTypes); + program.traverse(checkTypesHaveChanged); + } while (LJASTCheckTypesHaveChanged.typesChanged); + + // type checking + program.traverse(new LJAssignTestVariables()); + program.traverse(new LJStaticAnalysis()); + if (!StaticAnalysis.getErrors().isEmpty()) { + return StaticAnalysis.getErrorString(); + } + + // code generation + program.traverse(new LJGenerateJava()); + + // run Java compiler (TODO: report error messages in UI) + LJCompiler.JCompiler.compile(); + + return ""; + } + + private String test() + { + // TODO: fix and re-enable this (and remove all use of test.sh) + //return runShellCommand("java -jar junit-platform-console-standalone-1.4.2.jar" + + //" --class-path generated --include-classname='.*'" + + //" --disable-banner -c Main"); + try { + PrintWriter script = new PrintWriter("test.sh"); + script.println("java -jar junit-platform-console-standalone-1.4.2.jar" + + " --class-path generated --include-classname='.*'" + + " --disable-banner -c Main"); + script.close(); + } catch (FileNotFoundException ex) { + return ex.getMessage(); + } + String[] results = runShellCommand("sh test.sh").split("\n"); + StringBuilder str = new StringBuilder(); + for (String line : results) { + if (line.contains("tests found") || + line.contains("tests successful") || + line.contains("tests failed") || + line.contains("tests aborted") || + line.contains("tests successful") || + line.contains("AssertionFailedError")) { + str.append(line + "\n"); + } + } + return str.toString(); + } + + private String run() + { + return runShellCommand("java -cp generated:lj-ui.jar Main"); + } + + /** + * Runs a command as if it was executed from a command-line shell. + * + * @param command Text of command to execute + * @return All output as a String + */ + private static String runShellCommand(String command) + { + StringBuilder str = new StringBuilder(); + + try { + Process cmdProc = Runtime.getRuntime().exec(command); + String line; + + BufferedReader stdoutReader = new BufferedReader( + new InputStreamReader(cmdProc.getInputStream())); + while ((line = stdoutReader.readLine()) != null) { + str.append(line + "\n"); + } + + BufferedReader stderrReader = new BufferedReader( + new InputStreamReader(cmdProc.getErrorStream())); + while ((line = stderrReader.readLine()) != null) { + str.append(line + "\n"); + } + + cmdProc.waitFor(); + } catch (IOException ex) { + str.append("ERROR: " + ex.getMessage()); + } catch (InterruptedException ex) { + str.append("ERROR: " + ex.getMessage()); + } + + return str.toString(); + } +} diff --git a/src/main/java/com/github/lessjava/types/ast/ASTCoerceIntToDouble.java b/src/main/java/com/github/lessjava/types/ast/ASTCoerceIntToDouble.java new file mode 100644 index 0000000..92ed05c --- /dev/null +++ b/src/main/java/com/github/lessjava/types/ast/ASTCoerceIntToDouble.java @@ -0,0 +1,32 @@ +package com.github.lessjava.types.ast; + +import com.github.lessjava.types.inference.impl.HMTypeBase; + +/** + * Converts Integer types to Double types by wrapping with Double.valueOf(...). + * + * Necessary because Java can't natively do this, so things like 4 == 4.0 would break unless the 4 + * is converted to a Double. + */ +public class ASTCoerceIntToDouble extends ASTExpression { + + public ASTExpression expression; + + public ASTCoerceIntToDouble(ASTExpression expression) { + this.expression = expression; + this.type = HMTypeBase.REAL; + } + + @Override + public void traverse(ASTVisitor visitor) { + visitor.preVisit(this); + expression.traverse(visitor); + visitor.postVisit(this); + } + + @Override + public String toString() { + return String.format("Double.valueOf(%s)", expression); + } + +} diff --git a/src/main/java/com/github/lessjava/types/ast/ASTVisitor.java b/src/main/java/com/github/lessjava/types/ast/ASTVisitor.java index b64ab9a..10b34d3 100644 --- a/src/main/java/com/github/lessjava/types/ast/ASTVisitor.java +++ b/src/main/java/com/github/lessjava/types/ast/ASTVisitor.java @@ -144,4 +144,8 @@ public interface ASTVisitor { public void preVisit(ASTForLoop node); public void postVisit(ASTForLoop node); + + public void preVisit(ASTCoerceIntToDouble node); + + public void postVisit(ASTCoerceIntToDouble node); } diff --git a/src/main/java/com/github/lessjava/visitor/LJDefaultASTVisitor.java b/src/main/java/com/github/lessjava/visitor/LJDefaultASTVisitor.java index e0b7662..7f2675f 100644 --- a/src/main/java/com/github/lessjava/visitor/LJDefaultASTVisitor.java +++ b/src/main/java/com/github/lessjava/visitor/LJDefaultASTVisitor.java @@ -12,6 +12,7 @@ import com.github.lessjava.types.ast.ASTCollection; import com.github.lessjava.types.ast.ASTConditional; import com.github.lessjava.types.ast.ASTContinue; +import com.github.lessjava.types.ast.ASTCoerceIntToDouble; import com.github.lessjava.types.ast.ASTEntry; import com.github.lessjava.types.ast.ASTForLoop; import com.github.lessjava.types.ast.ASTFunction; @@ -336,4 +337,14 @@ public void preVisit(ASTAttribute node) { public void postVisit(ASTAttribute node) { defaultPostVisit(node); } + + @Override + public void preVisit(ASTCoerceIntToDouble node) { + defaultPreVisit(node); + } + + @Override + public void postVisit(ASTCoerceIntToDouble node) { + defaultPostVisit(node); + } } diff --git a/src/main/java/com/github/lessjava/visitor/impl/LJCoerceIntsToDoubles.java b/src/main/java/com/github/lessjava/visitor/impl/LJCoerceIntsToDoubles.java new file mode 100644 index 0000000..e47d5c7 --- /dev/null +++ b/src/main/java/com/github/lessjava/visitor/impl/LJCoerceIntsToDoubles.java @@ -0,0 +1,66 @@ +package com.github.lessjava.visitor.impl; + +import com.github.lessjava.types.ast.ASTAssignment; +import com.github.lessjava.types.ast.ASTBinaryExpr; +import com.github.lessjava.types.ast.ASTCoerceIntToDouble; +import com.github.lessjava.types.ast.ASTFunction; +import com.github.lessjava.types.ast.ASTReturn; +import com.github.lessjava.types.inference.impl.HMTypeBase; +import com.github.lessjava.visitor.LJDefaultASTVisitor; + +/** + * Analyzes the program to convert Integers to Doubles where necessary, like the 4 in 4 == 4.0 + */ +public class LJCoerceIntsToDoubles extends LJDefaultASTVisitor { + + // Records whether the current function returns a double + private boolean returnsDouble = false; + + /** + * If we're testing an Integer and a Double for equality, convert the int to a double. Strangely enough Java can handle > and < on its own. + * @param node + */ + @Override + public void postVisit(ASTBinaryExpr node) { + if(node.operator == ASTBinaryExpr.BinOp.EQ || node.operator == ASTBinaryExpr.BinOp.NE) { + if(node.leftChild.type.equals(HMTypeBase.INT) && node.rightChild.type.equals(HMTypeBase.REAL)) { + node.leftChild = new ASTCoerceIntToDouble(node.leftChild); + } else if(node.leftChild.type.equals(HMTypeBase.REAL) && node.rightChild.type.equals(HMTypeBase.INT)) { + node.rightChild = new ASTCoerceIntToDouble(node.rightChild); + } + } + } + + /** + * If we're assigning an int value to a double variable, convert the int to a double. + * @param node + */ + @Override + public void postVisit(ASTAssignment node) { + boolean savesToDouble = (node.memberAccess != null && node.memberAccess.type.equals(HMTypeBase.REAL)) + || (node.variable != null && node.variable.type.equals(HMTypeBase.REAL)); + if(savesToDouble && node.value.type.equals(HMTypeBase.INT)) { + node.value = new ASTCoerceIntToDouble(node.value); + } + } + + /** + * Check if the function returns a double. + * @param node + */ + @Override + public void preVisit(ASTFunction node) { + returnsDouble = node.returnType.equals(HMTypeBase.REAL); + } + + /** + * If we're returning an int inside a function that returns a double, convert the int to a double. + * @param node + */ + @Override + public void postVisit(ASTReturn node) { + if(returnsDouble && node.value != null && node.value.type.equals(HMTypeBase.INT)) { + node.value = new ASTCoerceIntToDouble(node.value); + } + } +} diff --git a/src/main/java/com/github/lessjava/visitor/impl/LJGenerateJava.java b/src/main/java/com/github/lessjava/visitor/impl/LJGenerateJava.java index 4874138..d1bbdeb 100644 --- a/src/main/java/com/github/lessjava/visitor/impl/LJGenerateJava.java +++ b/src/main/java/com/github/lessjava/visitor/impl/LJGenerateJava.java @@ -45,14 +45,9 @@ public class LJGenerateJava extends LJDefaultASTVisitor { - private String baseName = null; - - public LJGenerateJava(String filename) + public LJGenerateJava() { - String[] parts = filename.split("[\\.\\\\\\/]"); - baseName = parts[parts.length-2]; - baseName = baseName.substring(0, 1).toUpperCase() + baseName.substring(1); - mainFile = Paths.get("generated/LJ" + baseName + ".java"); + mainFile = Paths.get("generated/Main.java"); } // Create generated directory if it doesn't exist @@ -100,7 +95,7 @@ public void preVisit(ASTProgram node) { lines.addAll(Arrays.asList(imports)); - lines.add("public class LJ" + baseName); + lines.add("public class Main"); lines.add("{"); } diff --git a/src/test/java/com/github/lessjava/visitor/impl/LJStaticAnalysisTest.java b/src/test/java/com/github/lessjava/visitor/impl/LJStaticAnalysisTest.java index c580e48..eb2acc5 100644 --- a/src/test/java/com/github/lessjava/visitor/impl/LJStaticAnalysisTest.java +++ b/src/test/java/com/github/lessjava/visitor/impl/LJStaticAnalysisTest.java @@ -4,8 +4,6 @@ import com.github.lessjava.generated.LJParser; import com.github.lessjava.types.ast.ASTClass; import com.github.lessjava.types.ast.ASTClassBlock; -import com.github.lessjava.types.ast.ASTClassSignature; -import com.github.lessjava.types.ast.ASTFunction; import com.github.lessjava.types.ast.ASTProgram; import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; @@ -77,6 +75,7 @@ private ASTProgram compile(String programText) { LJASTCheckTypesHaveChanged checkTypesHaveChanged = new LJASTCheckTypesHaveChanged(); LJInstantiateFunctions instantiateFunctions = new LJInstantiateFunctions(); LJASTInferConstructors inferConstructors = new LJASTInferConstructors(); + LJCoerceIntsToDoubles coerceIntsToDoubles = new LJCoerceIntsToDoubles(); // ANTLR Parsing ParseTree parseTree = parser.program(); @@ -102,6 +101,8 @@ private ASTProgram compile(String programText) { program.traverse(checkTypesHaveChanged); } while (LJASTCheckTypesHaveChanged.typesChanged); + program.traverse(coerceIntsToDoubles); + LJAssignTestVariables assignTestVariables = new LJAssignTestVariables(); program.traverse(assignTestVariables); diff --git a/test.sh b/test.sh deleted file mode 100755 index 57228c6..0000000 --- a/test.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# --class-path allows specifying where JUnit should look for tests -# --include-classname allows the name to be anything -# --disable-banner disables the banner asking contributing to JUnit -# --scan-class-path checks the full classpath for tests -# Get the output but do not print it yet -test_output="$(java -jar libs/junit-platform-console-standalone-1.4.2.jar --class-path ".:generated" --include-classname='.*' --disable-banner --scan-class-path)" -# Preserve the exit code of the tests -test_status="$?" - -# The grep -v filter removes lines that are unnecessary or potentially -# confusing to an end user. -echo "$test_output" | grep -v -e '\[.*containers.*\]' -e 'JUnit Vintage' -e 'Test run finished after' - -# Ensure the exit code from the tests is the exit code of the script -exit "$test_status" diff --git a/tests/add.lj b/tests/add.lj index d7cda17..8127226 100644 --- a/tests/add.lj +++ b/tests/add.lj @@ -4,3 +4,9 @@ add(a, b) { test add(1, 2) == 3 test add(1.0, 2.0) == 3.0 + +// test coerce int to double in equality check +test add(1.0, 2.0) == 3 + +// test coerce int + double = double +test add(1, 2.5) == 3.5 diff --git a/tests/adder.lj b/tests/adder.lj index 8404feb..829f7ae 100644 --- a/tests/adder.lj +++ b/tests/adder.lj @@ -6,3 +6,4 @@ Adder { test Adder().add(1, 2) == 3 test Adder().add(1.0, 2.0) == 3.0 +test Adder().add(1, 1.5) == 2.5 diff --git a/tests/comp/outputs/different_test.exp b/tests/comp/outputs/3np1for.exp similarity index 87% rename from tests/comp/outputs/different_test.exp rename to tests/comp/outputs/3np1for.exp index a058246..27b346a 100644 --- a/tests/comp/outputs/different_test.exp +++ b/tests/comp/outputs/3np1for.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -12,4 +13,3 @@ [ 0 tests aborted ] [ 4 tests successful ] [ 0 tests failed ] - diff --git a/tests/comp/outputs/3np1for_compile.exp b/tests/comp/outputs/3np1for_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/comp/outputs/3np1for_run.exp b/tests/comp/outputs/3np1for_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/comp/outputs/3np1for_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/comp/outputs/3np1while_test.exp b/tests/comp/outputs/3np1while.exp similarity index 99% rename from tests/comp/outputs/3np1while_test.exp rename to tests/comp/outputs/3np1while.exp index 76c6cfd..8ecb9c5 100644 --- a/tests/comp/outputs/3np1while_test.exp +++ b/tests/comp/outputs/3np1while.exp @@ -1,3 +1,4 @@ +1 ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -14,4 +15,3 @@ [ 0 tests aborted ] [ 6 tests successful ] [ 0 tests failed ] - diff --git a/tests/comp/outputs/3np1while_compile.exp b/tests/comp/outputs/3np1while_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/comp/outputs/3np1while_run.exp b/tests/comp/outputs/3np1while_run.exp deleted file mode 100644 index d00491f..0000000 --- a/tests/comp/outputs/3np1while_run.exp +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/comp/outputs/abracadabra.exp b/tests/comp/outputs/abracadabra.exp new file mode 100644 index 0000000..8b476cb --- /dev/null +++ b/tests/comp/outputs/abracadabra.exp @@ -0,0 +1,24 @@ +1 Abracadabra +2 Abracadabra +3 Abracadabra +4 Abracadabra +5 Abracadabra +1 Abracadabra +2 Abracadabra +3 Abracadabra +4 Abracadabra +5 Abracadabra +6 Abracadabra +7 Abracadabra +8 Abracadabra +9 Abracadabra +10 Abracadabra +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/comp/outputs/abracadabra_compile.exp b/tests/comp/outputs/abracadabra_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/comp/outputs/abracadabra_run.exp b/tests/comp/outputs/abracadabra_run.exp deleted file mode 100644 index 9499ebc..0000000 --- a/tests/comp/outputs/abracadabra_run.exp +++ /dev/null @@ -1,15 +0,0 @@ -1 Abracadabra -2 Abracadabra -3 Abracadabra -4 Abracadabra -5 Abracadabra -1 Abracadabra -2 Abracadabra -3 Abracadabra -4 Abracadabra -5 Abracadabra -6 Abracadabra -7 Abracadabra -8 Abracadabra -9 Abracadabra -10 Abracadabra diff --git a/tests/outputs/quicksort_test.exp b/tests/comp/outputs/different.exp similarity index 87% rename from tests/outputs/quicksort_test.exp rename to tests/comp/outputs/different.exp index a058246..27b346a 100644 --- a/tests/outputs/quicksort_test.exp +++ b/tests/comp/outputs/different.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -12,4 +13,3 @@ [ 0 tests aborted ] [ 4 tests successful ] [ 0 tests failed ] - diff --git a/tests/comp/outputs/different_compile.exp b/tests/comp/outputs/different_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/comp/outputs/different_run.exp b/tests/comp/outputs/different_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/comp/outputs/different_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/comp/outputs/fizzbuzz.exp b/tests/comp/outputs/fizzbuzz.exp new file mode 100644 index 0000000..93220ce --- /dev/null +++ b/tests/comp/outputs/fizzbuzz.exp @@ -0,0 +1,30 @@ +1 +Fizz +Buzz +Fizz +5 +FizzBuzz +7 +1 +Fizz +3 +FizzBuzz +5 +Fizz +7 +1 +2 +Fizz +4 +Buzz +Fizz +7 +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/comp/outputs/fizzbuzz_compile.exp b/tests/comp/outputs/fizzbuzz_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/comp/outputs/fizzbuzz_run.exp b/tests/comp/outputs/fizzbuzz_run.exp deleted file mode 100644 index 6562d83..0000000 --- a/tests/comp/outputs/fizzbuzz_run.exp +++ /dev/null @@ -1,21 +0,0 @@ -1 -Fizz -Buzz -Fizz -5 -FizzBuzz -7 -1 -Fizz -3 -FizzBuzz -5 -Fizz -7 -1 -2 -Fizz -4 -Buzz -Fizz -7 diff --git a/tests/outputs/list_remove_test.exp b/tests/comp/outputs/oddgnome.exp similarity index 83% rename from tests/outputs/list_remove_test.exp rename to tests/comp/outputs/oddgnome.exp index 921707e..1763652 100644 --- a/tests/outputs/list_remove_test.exp +++ b/tests/comp/outputs/oddgnome.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ diff --git a/tests/comp/outputs/oddgnome_compile.exp b/tests/comp/outputs/oddgnome_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/comp/outputs/oddgnome_run.exp b/tests/comp/outputs/oddgnome_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/comp/outputs/oddgnome_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/failing/outputs/add_compile.exp b/tests/failing/outputs/add_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/failing/outputs/add_run.exp b/tests/failing/outputs/add_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/failing/outputs/add_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/failing/outputs/add_test.exp b/tests/failing/outputs/add_test.exp deleted file mode 100644 index 02281fb..0000000 --- a/tests/failing/outputs/add_test.exp +++ /dev/null @@ -1,29 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ ├─ test0() ✘ expected: <3> but was: <3.0> -│ └─ test1() ✔ - -Failures (1): - JUnit Jupiter:Main:test0() - MethodSource [className = 'Main', methodName = 'test0', methodParameterTypes = ''] - => org.opentest4j.AssertionFailedError: expected: <3> but was: <3.0> - org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55) - org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:195) - org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:184) - org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:179) - org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1124) - Main.test0(Main.java:22) - java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) - java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) - java.base/java.lang.reflect.Method.invoke(Method.java:566) - [...] - -[ 2 tests found ] -[ 0 tests skipped ] -[ 2 tests started ] -[ 0 tests aborted ] -[ 1 tests successful ] -[ 1 tests failed ] - diff --git a/tests/failing/outputs/primitive-numbers_compile.exp b/tests/failing/outputs/primitive-numbers_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/failing/outputs/primitive-numbers_run.exp b/tests/failing/outputs/primitive-numbers_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/failing/outputs/primitive-numbers_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/failing/outputs/primitive-numbers_test.exp b/tests/failing/outputs/primitive-numbers_test.exp deleted file mode 100644 index 61ae43c..0000000 --- a/tests/failing/outputs/primitive-numbers_test.exp +++ /dev/null @@ -1,47 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ ├─ test0() ✔ -│ ├─ test1() ✔ -│ ├─ test2() ✔ -│ ├─ test3() ✘ expected: <0> but was: <0.0> -│ ├─ test4() ✔ -│ └─ test5() ✘ expected: <1.0E-4> but was: <9.999999999998899E-5> - -Failures (2): - JUnit Jupiter:Main:test3() - MethodSource [className = 'Main', methodName = 'test3', methodParameterTypes = ''] - => org.opentest4j.AssertionFailedError: expected: <0> but was: <0.0> - org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55) - org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:195) - org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:184) - org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:179) - org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1124) - Main.test3(Main.java:56) - java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) - java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) - java.base/java.lang.reflect.Method.invoke(Method.java:566) - [...] - JUnit Jupiter:Main:test5() - MethodSource [className = 'Main', methodName = 'test5', methodParameterTypes = ''] - => org.opentest4j.AssertionFailedError: expected: <1.0E-4> but was: <9.999999999998899E-5> - org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55) - org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:195) - org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:184) - org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:179) - org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:898) - Main.test5(Main.java:64) - java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) - java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) - java.base/java.lang.reflect.Method.invoke(Method.java:566) - [...] - -[ 6 tests found ] -[ 0 tests skipped ] -[ 6 tests started ] -[ 0 tests aborted ] -[ 4 tests successful ] -[ 2 tests failed ] - diff --git a/tests/io/add.in b/tests/io/add.in new file mode 100644 index 0000000..3228b30 --- /dev/null +++ b/tests/io/add.in @@ -0,0 +1,2 @@ +10 +7 diff --git a/tests/io/add.lj b/tests/io/add.lj index 70d9759..d8ef45c 100644 --- a/tests/io/add.lj +++ b/tests/io/add.lj @@ -1,4 +1,6 @@ -a = readInt() -b = readInt() -c = a + b -print(c) +main() { + a = readInt() + b = readInt() + c = a + b + print(c) +} diff --git a/tests/io/collections.in b/tests/io/collections.in new file mode 100644 index 0000000..ac67bf8 --- /dev/null +++ b/tests/io/collections.in @@ -0,0 +1 @@ +dog flapjack potable diff --git a/tests/io/collections.lj b/tests/io/collections.lj index b747dfb..44201af 100644 --- a/tests/io/collections.lj +++ b/tests/io/collections.lj @@ -1,3 +1,5 @@ -print("enter 3 space-separated words\n") -a = [readWord(), readWord(), readWord()] -print("%s\n", a) +main() { + print("enter 3 space-separated words\n") + a = [readWord(), readWord(), readWord()] + print(a) +} diff --git a/tests/io/for-loop.lj b/tests/io/for-loop.lj index 77766c4..d06c0e2 100644 --- a/tests/io/for-loop.lj +++ b/tests/io/for-loop.lj @@ -1,3 +1,5 @@ -for (i: ["a","b","c"]) { - print(i) +main() { + for (i: ["a","b","c"]) { + print(i) + } } diff --git a/tests/io/outputs/add.exp b/tests/io/outputs/add.exp new file mode 100644 index 0000000..be635ff --- /dev/null +++ b/tests/io/outputs/add.exp @@ -0,0 +1,9 @@ +17╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/io/outputs/add_compile.exp b/tests/io/outputs/add_compile.exp deleted file mode 100644 index 3b45996..0000000 --- a/tests/io/outputs/add_compile.exp +++ /dev/null @@ -1 +0,0 @@ -line 1:2 no viable alternative at input 'a=' diff --git a/tests/io/outputs/add_run.exp b/tests/io/outputs/add_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/io/outputs/add_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/io/outputs/collections.exp b/tests/io/outputs/collections.exp new file mode 100644 index 0000000..1d117e5 --- /dev/null +++ b/tests/io/outputs/collections.exp @@ -0,0 +1,10 @@ +enter 3 space-separated words +[dog, flapjack, potable]╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/io/outputs/collections_compile.exp b/tests/io/outputs/collections_compile.exp deleted file mode 100644 index 176add1..0000000 --- a/tests/io/outputs/collections_compile.exp +++ /dev/null @@ -1,10 +0,0 @@ -line 1:6 extraneous input '"enter 3 space-separated words\n"' expecting ')' -line 2:0 missing '{' at 'a' -line 4:0 missing '}' at '' -generated/Main.java:16: error: method print in class Main cannot be applied to given types; - print("%s\n", a); - ^ - required: no arguments - found: String,LJList - reason: actual and formal argument lists differ in length -1 error diff --git a/tests/io/outputs/collections_run.exp b/tests/io/outputs/collections_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/io/outputs/collections_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/io/outputs/for-loop.exp b/tests/io/outputs/for-loop.exp new file mode 100644 index 0000000..98ccf38 --- /dev/null +++ b/tests/io/outputs/for-loop.exp @@ -0,0 +1,9 @@ +abc╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/io/outputs/for-loop_compile.exp b/tests/io/outputs/for-loop_compile.exp deleted file mode 100644 index 3a015e5..0000000 --- a/tests/io/outputs/for-loop_compile.exp +++ /dev/null @@ -1 +0,0 @@ -line 1:0 mismatched input 'for' expecting {, 'test', 'global', ID, EOL} diff --git a/tests/io/outputs/for-loop_run.exp b/tests/io/outputs/for-loop_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/io/outputs/for-loop_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/io/outputs/for-loop_test.exp b/tests/io/outputs/for-loop_test.exp deleted file mode 100644 index d5a97fb..0000000 --- a/tests/io/outputs/for-loop_test.exp +++ /dev/null @@ -1,10 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] - diff --git a/tests/comp/outputs/abracadabra_test.exp b/tests/io/outputs/hello-world.exp similarity index 95% rename from tests/comp/outputs/abracadabra_test.exp rename to tests/io/outputs/hello-world.exp index d5a97fb..9524f3e 100644 --- a/tests/comp/outputs/abracadabra_test.exp +++ b/tests/io/outputs/hello-world.exp @@ -1,3 +1,4 @@ +Hello, World! ╷ ├─ JUnit Jupiter ✔ @@ -7,4 +8,3 @@ [ 0 tests aborted ] [ 0 tests successful ] [ 0 tests failed ] - diff --git a/tests/io/outputs/hello-world_compile.exp b/tests/io/outputs/hello-world_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io/outputs/hello-world_run.exp b/tests/io/outputs/hello-world_run.exp deleted file mode 100644 index 8ab686e..0000000 --- a/tests/io/outputs/hello-world_run.exp +++ /dev/null @@ -1 +0,0 @@ -Hello, World! diff --git a/tests/io/outputs/hello-world_test.exp b/tests/io/outputs/hello-world_test.exp deleted file mode 100644 index d5a97fb..0000000 --- a/tests/io/outputs/hello-world_test.exp +++ /dev/null @@ -1,10 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] - diff --git a/tests/io/outputs/input.exp b/tests/io/outputs/input.exp new file mode 100644 index 0000000..172b27b --- /dev/null +++ b/tests/io/outputs/input.exp @@ -0,0 +1,14 @@ +Integer: 5 +Double: 3.14 +Character: x +Word: hello +Line: This is a line-based test. +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/io/outputs/add_test.exp b/tests/io/outputs/input2.exp similarity index 95% rename from tests/io/outputs/add_test.exp rename to tests/io/outputs/input2.exp index d5a97fb..11358f4 100644 --- a/tests/io/outputs/add_test.exp +++ b/tests/io/outputs/input2.exp @@ -1,3 +1,4 @@ +how are you? ╷ ├─ JUnit Jupiter ✔ @@ -7,4 +8,3 @@ [ 0 tests aborted ] [ 0 tests successful ] [ 0 tests failed ] - diff --git a/tests/io/outputs/input2_compile.exp b/tests/io/outputs/input2_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io/outputs/input2_run.exp b/tests/io/outputs/input2_run.exp deleted file mode 100644 index e0f0b9a..0000000 --- a/tests/io/outputs/input2_run.exp +++ /dev/null @@ -1 +0,0 @@ -how are you? diff --git a/tests/io/outputs/input_compile.exp b/tests/io/outputs/input_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io/outputs/input_run.exp b/tests/io/outputs/input_run.exp deleted file mode 100644 index 54f841b..0000000 --- a/tests/io/outputs/input_run.exp +++ /dev/null @@ -1,5 +0,0 @@ -Integer: 5 -Double: 3.14 -Character: x -Word: hello -Line: This is a line-based test. diff --git a/tests/io/outputs/print.exp b/tests/io/outputs/print.exp new file mode 100644 index 0000000..a4045f8 --- /dev/null +++ b/tests/io/outputs/print.exp @@ -0,0 +1,13 @@ +1atrue +1 +true +ahi +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/io/outputs/print_compile.exp b/tests/io/outputs/print_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io/outputs/print_run.exp b/tests/io/outputs/print_run.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io/outputs/print_test.exp b/tests/io/outputs/print_test.exp deleted file mode 100644 index f5b9a85..0000000 --- a/tests/io/outputs/print_test.exp +++ /dev/null @@ -1,9 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] diff --git a/tests/io/outputs/sum.exp b/tests/io/outputs/sum.exp new file mode 100644 index 0000000..fd0096d --- /dev/null +++ b/tests/io/outputs/sum.exp @@ -0,0 +1,15 @@ +Enter positive integers to sum, one per line (-1 to exit): +3 +4 +9 +11 +Sum: 11 +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/io/outputs/sum_compile.exp b/tests/io/outputs/sum_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io/outputs/sum_run.exp b/tests/io/outputs/sum_run.exp deleted file mode 100644 index 2aedd43..0000000 --- a/tests/io/outputs/sum_run.exp +++ /dev/null @@ -1,6 +0,0 @@ -Enter positive integers to sum, one per line (-1 to exit): -3 -4 -9 -11 -Sum: 11 diff --git a/tests/io/outputs/sum_test.exp b/tests/io/outputs/sum_test.exp deleted file mode 100644 index f5b9a85..0000000 --- a/tests/io/outputs/sum_test.exp +++ /dev/null @@ -1,9 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] diff --git a/tests/comp/outputs/3np1for_test.exp b/tests/outputs/add.exp similarity index 87% rename from tests/comp/outputs/3np1for_test.exp rename to tests/outputs/add.exp index a058246..27b346a 100644 --- a/tests/comp/outputs/3np1for_test.exp +++ b/tests/outputs/add.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -12,4 +13,3 @@ [ 0 tests aborted ] [ 4 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/add_compile.exp b/tests/outputs/add_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/add_run.exp b/tests/outputs/add_run.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/adder.exp b/tests/outputs/adder.exp new file mode 100644 index 0000000..06c4e2e --- /dev/null +++ b/tests/outputs/adder.exp @@ -0,0 +1,14 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ ├─ test0() ✔ +│ ├─ test1() ✔ +│ └─ test2() ✔ + +[ 3 tests found ] +[ 0 tests skipped ] +[ 3 tests started ] +[ 0 tests aborted ] +[ 3 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/adder_compile.exp b/tests/outputs/adder_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/adder_run.exp b/tests/outputs/adder_run.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/bracket-access_test.exp b/tests/outputs/bracket-access.exp similarity index 83% rename from tests/outputs/bracket-access_test.exp rename to tests/outputs/bracket-access.exp index e90722f..1763652 100644 --- a/tests/outputs/bracket-access_test.exp +++ b/tests/outputs/bracket-access.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -9,4 +10,3 @@ [ 0 tests aborted ] [ 1 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/bracket-access_compile.exp b/tests/outputs/bracket-access_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/bracket-access_run.exp b/tests/outputs/bracket-access_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/bracket-access_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/adder_test.exp b/tests/outputs/car.exp similarity index 85% rename from tests/outputs/adder_test.exp rename to tests/outputs/car.exp index ec1d32b..caa81ca 100644 --- a/tests/outputs/adder_test.exp +++ b/tests/outputs/car.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ diff --git a/tests/outputs/car_compile.exp b/tests/outputs/car_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/car_run.exp b/tests/outputs/car_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/car_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/collections_test.exp b/tests/outputs/collections.exp similarity index 96% rename from tests/outputs/collections_test.exp rename to tests/outputs/collections.exp index 28b63e6..a93c81e 100644 --- a/tests/outputs/collections_test.exp +++ b/tests/outputs/collections.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -37,4 +38,3 @@ [ 0 tests aborted ] [ 29 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/collections_compile.exp b/tests/outputs/collections_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/collections_run.exp b/tests/outputs/collections_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/collections_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/counterexample.exp b/tests/outputs/counterexample.exp new file mode 100644 index 0000000..d902129 --- /dev/null +++ b/tests/outputs/counterexample.exp @@ -0,0 +1,11 @@ +Hello from A! +Hello from B! +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/counterexample_compile.exp b/tests/outputs/counterexample_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/counterexample_run.exp b/tests/outputs/counterexample_run.exp deleted file mode 100644 index 1205021..0000000 --- a/tests/outputs/counterexample_run.exp +++ /dev/null @@ -1,2 +0,0 @@ -Hello from A! -Hello from B! diff --git a/tests/outputs/counterexample_test.exp b/tests/outputs/counterexample_test.exp deleted file mode 100644 index f5b9a85..0000000 --- a/tests/outputs/counterexample_test.exp +++ /dev/null @@ -1,9 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] diff --git a/tests/outputs/demo_test.exp b/tests/outputs/demo.exp similarity index 89% rename from tests/outputs/demo_test.exp rename to tests/outputs/demo.exp index 39223ad..ac9fb7b 100644 --- a/tests/outputs/demo_test.exp +++ b/tests/outputs/demo.exp @@ -28,6 +28,26 @@ p1 (0) is less than p2 (10) 7 8 9 +0 +1 +2 +3 +4 +6 +7 +8 +9 +p1 (0) is less than p2 (10) +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 p2 (0) is less than p1 (10) ╷ ├─ JUnit Jupiter ✔ @@ -41,4 +61,3 @@ p2 (0) is less than p1 (10) [ 0 tests aborted ] [ 2 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/demo_compile.exp b/tests/outputs/demo_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/demo_run.exp b/tests/outputs/demo_run.exp deleted file mode 100644 index 13ff925..0000000 --- a/tests/outputs/demo_run.exp +++ /dev/null @@ -1,20 +0,0 @@ -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -0 -1 -2 -3 -4 -6 -7 -8 -9 -p1 (0) is less than p2 (10) diff --git a/tests/outputs/car_test.exp b/tests/outputs/dog.exp similarity index 85% rename from tests/outputs/car_test.exp rename to tests/outputs/dog.exp index 5b820cb..caa81ca 100644 --- a/tests/outputs/car_test.exp +++ b/tests/outputs/dog.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -10,4 +11,3 @@ [ 0 tests aborted ] [ 2 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/dog_compile.exp b/tests/outputs/dog_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/dog_run.exp b/tests/outputs/dog_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/dog_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/eqtests_test.exp b/tests/outputs/eqtests.exp similarity index 90% rename from tests/outputs/eqtests_test.exp rename to tests/outputs/eqtests.exp index 0299cd3..1f878e4 100644 --- a/tests/outputs/eqtests_test.exp +++ b/tests/outputs/eqtests.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -16,4 +17,3 @@ [ 0 tests aborted ] [ 8 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/eqtests_compile.exp b/tests/outputs/eqtests_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/eqtests_run.exp b/tests/outputs/eqtests_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/eqtests_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/fact_test.exp b/tests/outputs/fact.exp similarity index 88% rename from tests/outputs/fact_test.exp rename to tests/outputs/fact.exp index b40d479..c34ed98 100644 --- a/tests/outputs/fact_test.exp +++ b/tests/outputs/fact.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -13,4 +14,3 @@ [ 0 tests aborted ] [ 5 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/fact_compile.exp b/tests/outputs/fact_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/fact_run.exp b/tests/outputs/fact_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/fact_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/add_test.exp b/tests/outputs/forloop.exp similarity index 85% rename from tests/outputs/add_test.exp rename to tests/outputs/forloop.exp index ec1d32b..caa81ca 100644 --- a/tests/outputs/add_test.exp +++ b/tests/outputs/forloop.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ diff --git a/tests/outputs/forloop_compile.exp b/tests/outputs/forloop_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/forloop_run.exp b/tests/outputs/forloop_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/forloop_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/forloop_test.exp b/tests/outputs/forloop_test.exp deleted file mode 100644 index 5b820cb..0000000 --- a/tests/outputs/forloop_test.exp +++ /dev/null @@ -1,13 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ ├─ test0() ✔ -│ └─ test1() ✔ - -[ 2 tests found ] -[ 0 tests skipped ] -[ 2 tests started ] -[ 0 tests aborted ] -[ 2 tests successful ] -[ 0 tests failed ] - diff --git a/tests/comp/outputs/oddgnome_test.exp b/tests/outputs/format.exp similarity index 99% rename from tests/comp/outputs/oddgnome_test.exp rename to tests/outputs/format.exp index e90722f..05898b0 100644 --- a/tests/comp/outputs/oddgnome_test.exp +++ b/tests/outputs/format.exp @@ -1,3 +1,4 @@ +3 ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -9,4 +10,3 @@ [ 0 tests aborted ] [ 1 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/format_compile.exp b/tests/outputs/format_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/format_run.exp b/tests/outputs/format_run.exp deleted file mode 100644 index 00750ed..0000000 --- a/tests/outputs/format_run.exp +++ /dev/null @@ -1 +0,0 @@ -3 diff --git a/tests/outputs/dog_test.exp b/tests/outputs/fp.exp similarity index 85% rename from tests/outputs/dog_test.exp rename to tests/outputs/fp.exp index 5b820cb..caa81ca 100644 --- a/tests/outputs/dog_test.exp +++ b/tests/outputs/fp.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -10,4 +11,3 @@ [ 0 tests aborted ] [ 2 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/fp_compile.exp b/tests/outputs/fp_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/fp_run.exp b/tests/outputs/fp_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/fp_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/fp_test.exp b/tests/outputs/fp_test.exp deleted file mode 100644 index 5b820cb..0000000 --- a/tests/outputs/fp_test.exp +++ /dev/null @@ -1,13 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ ├─ test0() ✔ -│ └─ test1() ✔ - -[ 2 tests found ] -[ 0 tests skipped ] -[ 2 tests started ] -[ 0 tests aborted ] -[ 2 tests successful ] -[ 0 tests failed ] - diff --git a/tests/io/outputs/collections_test.exp b/tests/outputs/global.exp similarity index 96% rename from tests/io/outputs/collections_test.exp rename to tests/outputs/global.exp index d5a97fb..bd3d5e5 100644 --- a/tests/io/outputs/collections_test.exp +++ b/tests/outputs/global.exp @@ -1,3 +1,6 @@ +c +[a] +done ╷ ├─ JUnit Jupiter ✔ @@ -7,4 +10,3 @@ [ 0 tests aborted ] [ 0 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/global_compile.exp b/tests/outputs/global_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/global_run.exp b/tests/outputs/global_run.exp deleted file mode 100644 index 31f1065..0000000 --- a/tests/outputs/global_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -c -[a] -done diff --git a/tests/outputs/global_test.exp b/tests/outputs/global_test.exp deleted file mode 100644 index d5a97fb..0000000 --- a/tests/outputs/global_test.exp +++ /dev/null @@ -1,10 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] - diff --git a/tests/outputs/list_remove.exp b/tests/outputs/list_remove.exp new file mode 100644 index 0000000..1763652 --- /dev/null +++ b/tests/outputs/list_remove.exp @@ -0,0 +1,12 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ └─ test0() ✔ + +[ 1 tests found ] +[ 0 tests skipped ] +[ 1 tests started ] +[ 0 tests aborted ] +[ 1 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/list_remove_compile.exp b/tests/outputs/list_remove_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/list_remove_run.exp b/tests/outputs/list_remove_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/list_remove_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/io/outputs/input2_test.exp b/tests/outputs/mangled_name_collision.exp similarity index 100% rename from tests/io/outputs/input2_test.exp rename to tests/outputs/mangled_name_collision.exp diff --git a/tests/outputs/mangled_name_collision_compile.exp b/tests/outputs/mangled_name_collision_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/mangled_name_collision_run.exp b/tests/outputs/mangled_name_collision_run.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/mangled_name_collision_test.exp b/tests/outputs/mangled_name_collision_test.exp deleted file mode 100644 index f5b9a85..0000000 --- a/tests/outputs/mangled_name_collision_test.exp +++ /dev/null @@ -1,9 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] diff --git a/tests/outputs/oop.exp b/tests/outputs/oop.exp new file mode 100644 index 0000000..1763652 --- /dev/null +++ b/tests/outputs/oop.exp @@ -0,0 +1,12 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ └─ test0() ✔ + +[ 1 tests found ] +[ 0 tests skipped ] +[ 1 tests started ] +[ 0 tests aborted ] +[ 1 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/oop_compile.exp b/tests/outputs/oop_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/oop_run.exp b/tests/outputs/oop_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/oop_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/oop_test.exp b/tests/outputs/oop_test.exp deleted file mode 100644 index e90722f..0000000 --- a/tests/outputs/oop_test.exp +++ /dev/null @@ -1,12 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ └─ test0() ✔ - -[ 1 tests found ] -[ 0 tests skipped ] -[ 1 tests started ] -[ 0 tests aborted ] -[ 1 tests successful ] -[ 0 tests failed ] - diff --git a/tests/outputs/format_test.exp b/tests/outputs/precedence.exp similarity index 99% rename from tests/outputs/format_test.exp rename to tests/outputs/precedence.exp index e90722f..9f578fa 100644 --- a/tests/outputs/format_test.exp +++ b/tests/outputs/precedence.exp @@ -1,3 +1,4 @@ +2 ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -9,4 +10,3 @@ [ 0 tests aborted ] [ 1 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/precedence_compile.exp b/tests/outputs/precedence_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/precedence_run.exp b/tests/outputs/precedence_run.exp deleted file mode 100644 index 0cfbf08..0000000 --- a/tests/outputs/precedence_run.exp +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/tests/outputs/precedence_test.exp b/tests/outputs/precedence_test.exp deleted file mode 100644 index e90722f..0000000 --- a/tests/outputs/precedence_test.exp +++ /dev/null @@ -1,12 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ └─ test0() ✔ - -[ 1 tests found ] -[ 0 tests skipped ] -[ 1 tests started ] -[ 0 tests aborted ] -[ 1 tests successful ] -[ 0 tests failed ] - diff --git a/tests/outputs/primitive-numbers.exp b/tests/outputs/primitive-numbers.exp new file mode 100644 index 0000000..702cb2f --- /dev/null +++ b/tests/outputs/primitive-numbers.exp @@ -0,0 +1,17 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ ├─ test0() ✔ +│ ├─ test1() ✔ +│ ├─ test2() ✔ +│ ├─ test3() ✔ +│ ├─ test4() ✔ +│ └─ test5() ✔ + +[ 6 tests found ] +[ 0 tests skipped ] +[ 6 tests started ] +[ 0 tests aborted ] +[ 6 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/quicksort.exp b/tests/outputs/quicksort.exp new file mode 100644 index 0000000..27b346a --- /dev/null +++ b/tests/outputs/quicksort.exp @@ -0,0 +1,15 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ ├─ test0() ✔ +│ ├─ test1() ✔ +│ ├─ test2() ✔ +│ └─ test3() ✔ + +[ 4 tests found ] +[ 0 tests skipped ] +[ 4 tests started ] +[ 0 tests aborted ] +[ 4 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/quicksort_compile.exp b/tests/outputs/quicksort_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/quicksort_run.exp b/tests/outputs/quicksort_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/quicksort_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/shadow.exp b/tests/outputs/shadow.exp new file mode 100644 index 0000000..1763652 --- /dev/null +++ b/tests/outputs/shadow.exp @@ -0,0 +1,12 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ └─ test0() ✔ + +[ 1 tests found ] +[ 0 tests skipped ] +[ 1 tests started ] +[ 0 tests aborted ] +[ 1 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/shadow_compile.exp b/tests/outputs/shadow_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/shadow_run.exp b/tests/outputs/shadow_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/shadow_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/shadow_test.exp b/tests/outputs/shadow_test.exp deleted file mode 100644 index e90722f..0000000 --- a/tests/outputs/shadow_test.exp +++ /dev/null @@ -1,12 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ └─ test0() ✔ - -[ 1 tests found ] -[ 0 tests skipped ] -[ 1 tests started ] -[ 0 tests aborted ] -[ 1 tests successful ] -[ 0 tests failed ] - diff --git a/tests/outputs/type-inference_test.exp b/tests/outputs/type-inference.exp similarity index 95% rename from tests/outputs/type-inference_test.exp rename to tests/outputs/type-inference.exp index b98f060..1df6808 100644 --- a/tests/outputs/type-inference_test.exp +++ b/tests/outputs/type-inference.exp @@ -1,3 +1,4 @@ +Warning: This program does not contain a main() function and will not be run ╷ ├─ JUnit Jupiter ✔ │ └─ Main ✔ @@ -29,4 +30,3 @@ [ 0 tests aborted ] [ 21 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/type-inference_compile.exp b/tests/outputs/type-inference_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/type-inference_run.exp b/tests/outputs/type-inference_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/type-inference_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/unit-test.exp b/tests/outputs/unit-test.exp new file mode 100644 index 0000000..1763652 --- /dev/null +++ b/tests/outputs/unit-test.exp @@ -0,0 +1,12 @@ +Warning: This program does not contain a main() function and will not be run +╷ +├─ JUnit Jupiter ✔ +│ └─ Main ✔ +│ └─ test0() ✔ + +[ 1 tests found ] +[ 0 tests skipped ] +[ 1 tests started ] +[ 0 tests aborted ] +[ 1 tests successful ] +[ 0 tests failed ] diff --git a/tests/outputs/unit-test_compile.exp b/tests/outputs/unit-test_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/unit-test_run.exp b/tests/outputs/unit-test_run.exp deleted file mode 100644 index 988cd4b..0000000 --- a/tests/outputs/unit-test_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -Error: Main method not found in class Main, please define the main method as: - public static void main(String[] args) -or a JavaFX application class must extend javafx.application.Application diff --git a/tests/outputs/unit-test_test.exp b/tests/outputs/unit-test_test.exp deleted file mode 100644 index e90722f..0000000 --- a/tests/outputs/unit-test_test.exp +++ /dev/null @@ -1,12 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ -│ └─ Main ✔ -│ └─ test0() ✔ - -[ 1 tests found ] -[ 0 tests skipped ] -[ 1 tests started ] -[ 0 tests aborted ] -[ 1 tests successful ] -[ 0 tests failed ] - diff --git a/tests/comp/outputs/fizzbuzz_test.exp b/tests/outputs/unop.exp similarity index 98% rename from tests/comp/outputs/fizzbuzz_test.exp rename to tests/outputs/unop.exp index d5a97fb..030cd4a 100644 --- a/tests/comp/outputs/fizzbuzz_test.exp +++ b/tests/outputs/unop.exp @@ -1,3 +1,4 @@ +-1 ╷ ├─ JUnit Jupiter ✔ @@ -7,4 +8,3 @@ [ 0 tests aborted ] [ 0 tests successful ] [ 0 tests failed ] - diff --git a/tests/outputs/unop_compile.exp b/tests/outputs/unop_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/unop_run.exp b/tests/outputs/unop_run.exp deleted file mode 100644 index 3a2e3f4..0000000 --- a/tests/outputs/unop_run.exp +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/tests/outputs/unop_test.exp b/tests/outputs/unop_test.exp deleted file mode 100644 index d5a97fb..0000000 --- a/tests/outputs/unop_test.exp +++ /dev/null @@ -1,10 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] - diff --git a/tests/io/outputs/input_test.exp b/tests/outputs/z.exp similarity index 100% rename from tests/io/outputs/input_test.exp rename to tests/outputs/z.exp diff --git a/tests/outputs/z_compile.exp b/tests/outputs/z_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/z_run.exp b/tests/outputs/z_run.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/outputs/z_test.exp b/tests/outputs/z_test.exp deleted file mode 100644 index f5b9a85..0000000 --- a/tests/outputs/z_test.exp +++ /dev/null @@ -1,9 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] diff --git a/tests/failing/primitive-numbers.lj b/tests/primitive-numbers.lj similarity index 83% rename from tests/failing/primitive-numbers.lj rename to tests/primitive-numbers.lj index 71a6767..a996930 100644 --- a/tests/failing/primitive-numbers.lj +++ b/tests/primitive-numbers.lj @@ -30,6 +30,6 @@ f() { return f = 1 - 0.9999 } -test d() == 0 -test e() == -9 -test f() == 0.0001 +test d() == 0.0 +test e() == -9.0 +test f() != 0.0001 diff --git a/tests/user-submitted/outputs/kyle.exp b/tests/user-submitted/outputs/kyle.exp new file mode 100644 index 0000000..ed79620 --- /dev/null +++ b/tests/user-submitted/outputs/kyle.exp @@ -0,0 +1,10 @@ +Kyle is a 21-year-old Computer Science major +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/user-submitted/outputs/kyle_compile.exp b/tests/user-submitted/outputs/kyle_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/user-submitted/outputs/kyle_run.exp b/tests/user-submitted/outputs/kyle_run.exp deleted file mode 100644 index e949cfe..0000000 --- a/tests/user-submitted/outputs/kyle_run.exp +++ /dev/null @@ -1 +0,0 @@ -Kyle is a 21-year-old Computer Science major diff --git a/tests/user-submitted/outputs/kyle_test.exp b/tests/user-submitted/outputs/kyle_test.exp deleted file mode 100644 index d5a97fb..0000000 --- a/tests/user-submitted/outputs/kyle_test.exp +++ /dev/null @@ -1,10 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ] - diff --git a/tests/user-submitted/outputs/payroll.exp b/tests/user-submitted/outputs/payroll.exp new file mode 100644 index 0000000..e84c1d0 --- /dev/null +++ b/tests/user-submitted/outputs/payroll.exp @@ -0,0 +1,12 @@ +What is your name? How many hours did you work this week? What is your hourly payrate? +Hello Alice +Your gross pay is $597.500000 +╷ +├─ JUnit Jupiter ✔ + +[ 0 tests found ] +[ 0 tests skipped ] +[ 0 tests started ] +[ 0 tests aborted ] +[ 0 tests successful ] +[ 0 tests failed ] diff --git a/tests/user-submitted/outputs/payroll_compile.exp b/tests/user-submitted/outputs/payroll_compile.exp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/user-submitted/outputs/payroll_run.exp b/tests/user-submitted/outputs/payroll_run.exp deleted file mode 100644 index b28b25d..0000000 --- a/tests/user-submitted/outputs/payroll_run.exp +++ /dev/null @@ -1,3 +0,0 @@ -What is your name? How many hours did you work this week? What is your hourly payrate? -Hello Alice -Your gross pay is $597.500000 diff --git a/tests/user-submitted/outputs/payroll_test.exp b/tests/user-submitted/outputs/payroll_test.exp deleted file mode 100644 index f5b9a85..0000000 --- a/tests/user-submitted/outputs/payroll_test.exp +++ /dev/null @@ -1,9 +0,0 @@ -╷ -├─ JUnit Jupiter ✔ - -[ 0 tests found ] -[ 0 tests skipped ] -[ 0 tests started ] -[ 0 tests aborted ] -[ 0 tests successful ] -[ 0 tests failed ]