From 6fa132313d2d8e0e91156d6fedd07d8c6fa71837 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sat, 11 Feb 2017 10:42:07 -0500 Subject: [PATCH] Refactored error severity --- src/error/CriticalLineColumnException.java | 21 ++++++ src/error/CriticalLispException.java | 16 +++++ src/error/ErrorManager.java | 68 ++++++++++++++++--- src/error/LispException.java | 8 ++- src/error/LispWarning.java | 16 +++++ src/function/builtin/LOAD.java | 12 ++-- src/function/builtin/special/DEFUN.java | 27 +++++--- src/interpreter/LispInterpreter.java | 2 +- .../LispInterpreterBuilderImpl.java | 16 +---- src/scanner/LispInputStream.java | 16 +---- src/token/TokenFactory.java | 7 +- test/error/ErrorManagerTester.java | 61 ++++++++++++++--- test/function/ArgumentValidatorTester.java | 10 +-- test/function/builtin/LOADTester.java | 32 ++++++--- .../function/builtin/special/DEFUNTester.java | 12 ++-- test/parser/LispParserTester.java | 9 +-- .../LispCommentRemovingInputStreamTester.java | 6 +- test/scanner/LispScannerTypeTester.java | 6 +- test/sexpression/SExpressionTester.java | 4 +- test/token/TokenFactoryTester.java | 4 +- 20 files changed, 248 insertions(+), 105 deletions(-) create mode 100644 src/error/CriticalLineColumnException.java create mode 100644 src/error/CriticalLispException.java create mode 100644 src/error/LispWarning.java diff --git a/src/error/CriticalLineColumnException.java b/src/error/CriticalLineColumnException.java new file mode 100644 index 0000000..a8c2cc5 --- /dev/null +++ b/src/error/CriticalLineColumnException.java @@ -0,0 +1,21 @@ +package error; + +import static error.ErrorManager.Severity.CRITICAL; + +import error.ErrorManager.Severity; +import file.FilePosition; + +public abstract class CriticalLineColumnException extends LineColumnException { + + private static final long serialVersionUID = 1L; + + public CriticalLineColumnException(FilePosition position) { + super(position); + } + + @Override + public Severity getSeverity() { + return CRITICAL; + } + +} \ No newline at end of file diff --git a/src/error/CriticalLispException.java b/src/error/CriticalLispException.java new file mode 100644 index 0000000..b0bb04b --- /dev/null +++ b/src/error/CriticalLispException.java @@ -0,0 +1,16 @@ +package error; + +import static error.ErrorManager.Severity.CRITICAL; + +import error.ErrorManager.Severity; + +public abstract class CriticalLispException extends LispException { + + private static final long serialVersionUID = 1L; + + @Override + public Severity getSeverity() { + return CRITICAL; + } + +} diff --git a/src/error/ErrorManager.java b/src/error/ErrorManager.java index da713e4..55497d9 100644 --- a/src/error/ErrorManager.java +++ b/src/error/ErrorManager.java @@ -1,5 +1,8 @@ package error; +import static error.ErrorManager.Severity.*; + +import java.io.PrintStream; import java.text.MessageFormat; import environment.RuntimeEnvironment; @@ -9,11 +12,10 @@ import environment.RuntimeEnvironment; */ public class ErrorManager { - public static final int CRITICAL_LEVEL = 3; - private static final String ANSI_RESET = "\u001B[0m"; private static final String ANSI_RED = "\u001B[31m"; private static final String ANSI_PURPLE = "\u001B[35m"; + private static final String ANSI_YELLOW = "\u001B[33m"; private RuntimeEnvironment environment; @@ -21,26 +23,72 @@ public class ErrorManager { this.environment = RuntimeEnvironment.getInstance(); } - public void generateError(LispException lispException) { - printError(lispException); + public void handle(LispException lispException) { + printMessage(lispException); if (isCritical(lispException)) environment.terminateExceptionally(); } - private void printError(LispException lispException) { - String formattedMessage = formatMessage(lispException); - environment.getErrorOutput().println(formattedMessage); + private void printMessage(LispException lispException) { + PrintStream output = selectOutputStream(lispException.getSeverity()); + output.println(formatMessage(lispException)); + } + + private PrintStream selectOutputStream(Severity severity) { + if (severity == WARNING) + return environment.getOutput(); + + return environment.getErrorOutput(); } private String formatMessage(LispException lispException) { - String color = isCritical(lispException) ? ANSI_PURPLE : ANSI_RED; + Severity severity = lispException.getSeverity(); + String color = severity.getMessageColor(); + String prefix = severity.toDisplayString(); - return MessageFormat.format("{0}error: {1}{2}", color, lispException.getMessage(), ANSI_RESET); + return MessageFormat.format("{0}{1}: {2}{3}", color, prefix, lispException.getMessage(), ANSI_RESET); } private boolean isCritical(LispException lispException) { - return lispException.getSeverity() >= CRITICAL_LEVEL; + return lispException.getSeverity() == CRITICAL; + } + + public static enum Severity { + WARNING { + + public String getMessageColor() { + return ANSI_YELLOW; + } + + public String toDisplayString() { + return "warning"; + } + }, + ERROR { + + public String getMessageColor() { + return ANSI_RED; + } + + public String toDisplayString() { + return "error"; + } + }, + CRITICAL { + + public String getMessageColor() { + return ANSI_PURPLE; + } + + public String toDisplayString() { + return "critical"; + } + }; + + public abstract String getMessageColor(); + + public abstract String toDisplayString(); } } diff --git a/src/error/LispException.java b/src/error/LispException.java index 41e499b..32eb330 100644 --- a/src/error/LispException.java +++ b/src/error/LispException.java @@ -1,11 +1,15 @@ package error; +import static error.ErrorManager.Severity.ERROR; + +import error.ErrorManager.Severity; + public abstract class LispException extends RuntimeException { private static final long serialVersionUID = 1L; - public int getSeverity() { - return 0; + public Severity getSeverity() { + return ERROR; } } diff --git a/src/error/LispWarning.java b/src/error/LispWarning.java new file mode 100644 index 0000000..a6351dc --- /dev/null +++ b/src/error/LispWarning.java @@ -0,0 +1,16 @@ +package error; + +import static error.ErrorManager.Severity.WARNING; + +import error.ErrorManager.Severity; + +public abstract class LispWarning extends LispException { + + private static final long serialVersionUID = 1L; + + @Override + public Severity getSeverity() { + return WARNING; + } + +} diff --git a/src/function/builtin/LOAD.java b/src/function/builtin/LOAD.java index f5f83c2..d161b15 100644 --- a/src/function/builtin/LOAD.java +++ b/src/function/builtin/LOAD.java @@ -12,15 +12,13 @@ import sexpression.*; public class LOAD extends LispFunction { private ArgumentValidator argumentValidator; - private RuntimeEnvironment environment; private ErrorManager errorManager; public LOAD() { this.argumentValidator = new ArgumentValidator("LOAD"); this.argumentValidator.setExactNumberOfArguments(1); this.argumentValidator.setEveryArgumentExpectedType(LispString.class); - this.environment = RuntimeEnvironment.getInstance(); - this.errorManager = this.environment.getErrorManager(); + this.errorManager = RuntimeEnvironment.getInstance().getErrorManager(); } public SExpression call(Cons argumentList) { @@ -52,7 +50,7 @@ public class LOAD extends LispFunction { try { parser = new LispParser(new FileInputStream(fileName), fileName); } catch (FileNotFoundException e) { - errorManager.generateError(new CouldNotLoadFileException(fileName)); + errorManager.handle(new CouldNotLoadFileWarning(fileName)); } return parser; @@ -63,7 +61,7 @@ public class LOAD extends LispFunction { try { EVAL.eval(parser.getNextSExpression()); } catch (LispException e) { - errorManager.generateError(e); + errorManager.handle(e); return false; } } @@ -71,12 +69,12 @@ public class LOAD extends LispFunction { return true; } - public static class CouldNotLoadFileException extends LispException { + public static class CouldNotLoadFileWarning extends LispWarning { private static final long serialVersionUID = 1L; private String fileName; - public CouldNotLoadFileException(String fileName) { + public CouldNotLoadFileWarning(String fileName) { this.fileName = fileName; } diff --git a/src/function/builtin/special/DEFUN.java b/src/function/builtin/special/DEFUN.java index 1fa85fa..8ccf077 100644 --- a/src/function/builtin/special/DEFUN.java +++ b/src/function/builtin/special/DEFUN.java @@ -3,6 +3,7 @@ package function.builtin.special; import java.text.MessageFormat; import environment.RuntimeEnvironment; +import error.*; import function.*; import function.builtin.cons.LIST; import sexpression.*; @@ -13,7 +14,7 @@ public class DEFUN extends LispFunction { private ArgumentValidator argumentValidator; private ArgumentValidator lambdaListIsListValidator; private ArgumentValidator lambdaListValidator; - private RuntimeEnvironment environment; + private ErrorManager errorManager; public DEFUN() { this.argumentValidator = new ArgumentValidator("DEFUN"); @@ -26,7 +27,7 @@ public class DEFUN extends LispFunction { this.lambdaListValidator = new ArgumentValidator("DEFUN|parameter|"); this.lambdaListValidator.setEveryArgumentExpectedType(Symbol.class); - this.environment = RuntimeEnvironment.getInstance(); + this.errorManager = RuntimeEnvironment.getInstance().getErrorManager(); } public SExpression call(Cons argumentList) { @@ -44,20 +45,30 @@ public class DEFUN extends LispFunction { UserDefinedFunction function = new UserDefinedFunction(functionName.toString(), lambdaList, functionBody); if (FunctionTable.isAlreadyDefined(functionName.toString())) - printWarning(functionName); + errorManager.handle(new RedefiningFunctionWarning(functionName.toString())); FunctionTable.defineFunction(functionName.toString(), function); return functionName; } - private void printWarning(SExpression functionName) { - String message = MessageFormat.format("WARNING: redefining function {0}", functionName.toString()); - environment.getOutput().println(message); - } - public boolean evaluateArguments() { return false; } + public class RedefiningFunctionWarning extends LispWarning { + + private static final long serialVersionUID = 1L; + private String functionName; + + public RedefiningFunctionWarning(String functionName) { + this.functionName = functionName; + } + + @Override + public String getMessage() { + return MessageFormat.format("redefining function {0}", functionName); + } + } + } diff --git a/src/interpreter/LispInterpreter.java b/src/interpreter/LispInterpreter.java index a10621f..40724cc 100644 --- a/src/interpreter/LispInterpreter.java +++ b/src/interpreter/LispInterpreter.java @@ -41,7 +41,7 @@ public class LispInterpreter { printValueOfNextSExpressionWithException(); } catch (LispException e) { erasePrompt(); - errorManager.generateError(e); + errorManager.handle(e); } } diff --git a/src/interpreter/LispInterpreterBuilderImpl.java b/src/interpreter/LispInterpreterBuilderImpl.java index 20f30cb..cc8842b 100644 --- a/src/interpreter/LispInterpreterBuilderImpl.java +++ b/src/interpreter/LispInterpreterBuilderImpl.java @@ -100,7 +100,7 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder { try { environment.setInput(getInputStream()); } catch (FileNotFoundException e) { - errorManager.generateError(new LispFileNotFoundException(e)); + errorManager.handle(new LispFileNotFoundException(e)); } } @@ -112,22 +112,17 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder { return isInteractive ? new InteractiveLispInterpreter() : new LispInterpreter(); } - public class InterpreterAlreadyBuiltException extends LispException { + public class InterpreterAlreadyBuiltException extends CriticalLispException { private static final long serialVersionUID = 1L; - @Override - public int getSeverity() { - return ErrorManager.CRITICAL_LEVEL; - } - @Override public String getMessage() { return "Refusing to build more than one interpreter."; } } - public static class LispFileNotFoundException extends LispException { + public static class LispFileNotFoundException extends CriticalLispException { private static final long serialVersionUID = 1L; private String message; @@ -136,11 +131,6 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder { this.message = e.getMessage(); } - @Override - public int getSeverity() { - return ErrorManager.CRITICAL_LEVEL; - } - @Override public String getMessage() { return message; diff --git a/src/scanner/LispInputStream.java b/src/scanner/LispInputStream.java index 76da488..90222e9 100644 --- a/src/scanner/LispInputStream.java +++ b/src/scanner/LispInputStream.java @@ -2,7 +2,7 @@ package scanner; import java.io.IOException; -import error.*; +import error.CriticalLispException; public interface LispInputStream { @@ -10,17 +10,12 @@ public interface LispInputStream { void unreadLastCharacter(); - public static class MaximumUnreadsExceededException extends LispException { + public static class MaximumUnreadsExceededException extends CriticalLispException { private static final long serialVersionUID = 1L; - - @Override - public int getSeverity() { - return ErrorManager.CRITICAL_LEVEL; - } } - public static class UncheckedIOException extends LispException { + public static class UncheckedIOException extends CriticalLispException { private static final long serialVersionUID = 1L; private IOException ioException; @@ -29,11 +24,6 @@ public interface LispInputStream { this.ioException = ioException; } - @Override - public int getSeverity() { - return ErrorManager.CRITICAL_LEVEL; - } - @Override public String getMessage() { return ioException.getMessage(); diff --git a/src/token/TokenFactory.java b/src/token/TokenFactory.java index 3123aba..d524306 100644 --- a/src/token/TokenFactory.java +++ b/src/token/TokenFactory.java @@ -11,7 +11,7 @@ public interface TokenFactory { Token createEOFToken(FilePosition position); - public static class EmptyTokenTextException extends LineColumnException { + public static class EmptyTokenTextException extends CriticalLineColumnException { private static final long serialVersionUID = 1L; @@ -19,11 +19,6 @@ public interface TokenFactory { super(position); } - @Override - public int getSeverity() { - return ErrorManager.CRITICAL_LEVEL; - } - @Override public String getMessagePrefix() { return "empty token"; diff --git a/test/error/ErrorManagerTester.java b/test/error/ErrorManagerTester.java index a28e294..2882662 100644 --- a/test/error/ErrorManagerTester.java +++ b/test/error/ErrorManagerTester.java @@ -1,5 +1,6 @@ package error; +import static error.ErrorManager.Severity.*; import static org.junit.Assert.*; import java.io.*; @@ -8,6 +9,7 @@ import java.util.*; import org.junit.*; import environment.RuntimeEnvironment; +import error.ErrorManager.Severity; public class ErrorManagerTester { @@ -15,22 +17,24 @@ public class ErrorManagerTester { private static final String MESSAGE = "message"; private Set indicatorSet; + private ByteArrayOutputStream errorOutputStream; private ByteArrayOutputStream outputStream; private ErrorManager createErrorManagerWithIndicators() { RuntimeEnvironment.getInstance().setErrorTerminationFunction(() -> indicatorSet.add(TERMINATED)); - RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(outputStream)); + RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(errorOutputStream)); + RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream)); return new ErrorManager(); } - private LispException createLispException(int severity) { + private LispException createLispException(Severity severity) { return new LispException() { private static final long serialVersionUID = 1L; @Override - public int getSeverity() { + public Severity getSeverity() { return severity; } @@ -49,17 +53,26 @@ public class ErrorManagerTester { assertFalse(indicatorSet.contains(TERMINATED)); } - private void assertErrorMessageNotWritten() { + private void assertWarningMessageNotWritten() { assertTrue(outputStream.toByteArray().length == 0); } - private void assertErrorMessageWritten() { + private void assertWarningMessageWritten() { assertTrue(outputStream.toByteArray().length > 0); } + private void assertErrorMessageNotWritten() { + assertTrue(errorOutputStream.toByteArray().length == 0); + } + + private void assertErrorMessageWritten() { + assertTrue(errorOutputStream.toByteArray().length > 0); + } + @Before public void setUp() { this.indicatorSet = new HashSet<>(); + this.errorOutputStream = new ByteArrayOutputStream(); this.outputStream = new ByteArrayOutputStream(); } @@ -67,24 +80,43 @@ public class ErrorManagerTester { public void givenCriticalExceptionSeverity_RunsProvidedTerminationFunction() { ErrorManager errorManager = createErrorManagerWithIndicators(); - errorManager.generateError(createLispException(ErrorManager.CRITICAL_LEVEL)); + errorManager.handle(createLispException(CRITICAL)); assertTerminated(); } @Test - public void givenNonCriticalExceptionSeverity_DoesNotRunProvidedTerminationFunction() { + public void givenWarningExceptionSeverity_DoesNotRunProvidedTerminationFunction() { ErrorManager errorManager = createErrorManagerWithIndicators(); - errorManager.generateError(createLispException(0)); + errorManager.handle(createLispException(WARNING)); assertNotTerminated(); } @Test - public void usesOutputFunctionToDisplayMessages_NoTermination() { + public void givenErrorExceptionSeverity_DoesNotRunProvidedTerminationFunction() { ErrorManager errorManager = createErrorManagerWithIndicators(); - errorManager.generateError(createLispException(0)); + errorManager.handle(createLispException(ERROR)); assertNotTerminated(); + } + + @Test + public void usesOutputToDisplayWarningMessage() { + ErrorManager errorManager = createErrorManagerWithIndicators(); + + errorManager.handle(createLispException(WARNING)); + assertNotTerminated(); + assertErrorMessageNotWritten(); + assertWarningMessageWritten(); + } + + @Test + public void usesErrorOutputToDisplayErrorMessage() { + ErrorManager errorManager = createErrorManagerWithIndicators(); + + errorManager.handle(createLispException(ERROR)); + assertNotTerminated(); + assertWarningMessageNotWritten(); assertErrorMessageWritten(); } @@ -100,9 +132,16 @@ public class ErrorManagerTester { public void usesOutputFunctionToDisplayMessages_WithTermination() { ErrorManager errorManager = createErrorManagerWithIndicators(); - errorManager.generateError(createLispException(ErrorManager.CRITICAL_LEVEL)); + errorManager.handle(createLispException(CRITICAL)); assertTerminated(); assertErrorMessageWritten(); } + @Test + public void severityCoverage() { + Severity.valueOf(WARNING.toString()); + Severity.valueOf(ERROR.toString()); + Severity.valueOf(CRITICAL.toString()); + } + } diff --git a/test/function/ArgumentValidatorTester.java b/test/function/ArgumentValidatorTester.java index 97ae1d3..24bf0e5 100644 --- a/test/function/ArgumentValidatorTester.java +++ b/test/function/ArgumentValidatorTester.java @@ -1,10 +1,10 @@ package function; +import static error.ErrorManager.Severity.ERROR; import static org.junit.Assert.*; import org.junit.*; -import error.ErrorManager; import function.ArgumentValidator.*; import sexpression.*; @@ -75,7 +75,7 @@ public class ArgumentValidatorTester { public void tooManyArgumentsException_HasCorrectSeverity() { TooManyArgumentsException e = new TooManyArgumentsException("TEST", Nil.getInstance()); - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } @Test @@ -90,7 +90,7 @@ public class ArgumentValidatorTester { public void tooFewArgumentsException_HasCorrectSeverity() { TooFewArgumentsException e = new TooFewArgumentsException("TEST", Nil.getInstance()); - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } @Test @@ -105,7 +105,7 @@ public class ArgumentValidatorTester { public void BadArgumentTypeException_HasCorrectSeverity() { BadArgumentTypeException e = new BadArgumentTypeException("TEST", Nil.getInstance(), SExpression.class); - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } @Test @@ -188,7 +188,7 @@ public class ArgumentValidatorTester { public void DottedArgumentListException_HasCorrectSeverity() { DottedArgumentListException e = new DottedArgumentListException("TEST", Nil.getInstance()); - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } @Test diff --git a/test/function/builtin/LOADTester.java b/test/function/builtin/LOADTester.java index 7b9d85b..4c37c8a 100644 --- a/test/function/builtin/LOADTester.java +++ b/test/function/builtin/LOADTester.java @@ -1,39 +1,51 @@ package function.builtin; -import static org.junit.Assert.*; -import static testutil.TestUtilities.*; +import static org.junit.Assert.assertTrue; +import static testutil.TestUtilities.evaluateString; +import static testutil.TypeAssertions.*; import java.io.*; import org.junit.*; import environment.RuntimeEnvironment; +import error.ErrorManager; import function.ArgumentValidator.*; -import sexpression.*; public class LOADTester { private ByteArrayOutputStream outputStream; + private ByteArrayOutputStream errorOutputStream; - private void assertSomethingPrinted() { + private void assertWarningMessagePrinted() { assertTrue(outputStream.toByteArray().length > 0); + assertTrue(errorOutputStream.toByteArray().length == 0); + } + + private void assertErrorMessagePrinted() { + assertTrue(errorOutputStream.toByteArray().length > 0); + assertTrue(outputStream.toByteArray().length == 0); } private void assertNothingPrinted() { assertTrue(outputStream.toByteArray().length == 0); + assertTrue(outputStream.toByteArray().length == 0); } @Before public void setUp() { this.outputStream = new ByteArrayOutputStream(); - RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(outputStream)); + this.errorOutputStream = new ByteArrayOutputStream(); + RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream)); + RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(errorOutputStream)); + RuntimeEnvironment.getInstance().setErrorManager(new ErrorManager()); } @Test public void loadGoodFile_ReturnsTAndPrintsNothing() { String input = "(load \"test/function/builtin/test-files/load-good.lisp\")"; - assertSExpressionsMatch(Symbol.T, evaluateString(input)); + assertT(evaluateString(input)); assertNothingPrinted(); } @@ -41,16 +53,16 @@ public class LOADTester { public void loadBadFile_ReturnsNilAndPrintsError() { String input = "(load \"test/function/builtin/test-files/load-bad.lisp\")"; - assertSExpressionsMatch(Nil.getInstance(), evaluateString(input)); - assertSomethingPrinted(); + assertNil(evaluateString(input)); + assertErrorMessagePrinted(); } @Test public void loadNonExistentFile_ReturnsNilAndPrintsError() { String input = "(load \"doesNotExist.lisp\")"; - assertSExpressionsMatch(Nil.getInstance(), evaluateString(input)); - assertSomethingPrinted(); + assertNil(evaluateString(input)); + assertWarningMessagePrinted(); } @Test(expected = BadArgumentTypeException.class) diff --git a/test/function/builtin/special/DEFUNTester.java b/test/function/builtin/special/DEFUNTester.java index 21ab446..49e36de 100644 --- a/test/function/builtin/special/DEFUNTester.java +++ b/test/function/builtin/special/DEFUNTester.java @@ -1,6 +1,6 @@ package function.builtin.special; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static testutil.TestUtilities.*; import java.io.*; @@ -8,6 +8,7 @@ import java.io.*; import org.junit.*; import environment.RuntimeEnvironment; +import error.ErrorManager; import function.ArgumentValidator.*; import table.FunctionTable; @@ -15,14 +16,15 @@ public class DEFUNTester { private ByteArrayOutputStream outputStream; - private void assertPrinted(String expected) { - assertEquals(expected, outputStream.toString()); + private void assertSomethingPrinted() { + assertTrue(outputStream.toByteArray().length > 0); } @Before public void setUp() { this.outputStream = new ByteArrayOutputStream(); RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream)); + RuntimeEnvironment.getInstance().setErrorManager(new ErrorManager()); FunctionTable.reset(); } @@ -53,7 +55,7 @@ public class DEFUNTester { evaluateString(input); evaluateString(input); - assertPrinted("WARNING: redefining function MYFUNCTION\n"); + assertSomethingPrinted(); } @Test @@ -61,7 +63,7 @@ public class DEFUNTester { evaluateString("(defun myFunction2 () nil)"); evaluateString("(defun myFunction2 () T)"); - assertPrinted("WARNING: redefining function MYFUNCTION2\n"); + assertSomethingPrinted(); assertSExpressionsMatch(parseString("t"), evaluateString("(myFunction2)")); } diff --git a/test/parser/LispParserTester.java b/test/parser/LispParserTester.java index a683df2..fcf4b78 100644 --- a/test/parser/LispParserTester.java +++ b/test/parser/LispParserTester.java @@ -1,5 +1,6 @@ package parser; +import static error.ErrorManager.Severity.ERROR; import static org.junit.Assert.*; import static testutil.TestUtilities.*; import static testutil.TypeAssertions.*; @@ -8,7 +9,7 @@ import java.io.InputStream; import org.junit.Test; -import error.*; +import error.LispException; import scanner.LispInputStream.UncheckedIOException; import scanner.LispScanner.UnterminatedStringException; import token.Eof.EofEncounteredException; @@ -188,7 +189,7 @@ public class LispParserTester { try { parser.getNextSExpression(); } catch (BadCharacterException e) { - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } } @@ -231,7 +232,7 @@ public class LispParserTester { try { parser.getNextSExpression(); } catch (EofEncounteredException e) { - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } } @@ -266,7 +267,7 @@ public class LispParserTester { try { parser.getNextSExpression(); } catch (StartsWithRightParenthesisException e) { - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } } diff --git a/test/scanner/LispCommentRemovingInputStreamTester.java b/test/scanner/LispCommentRemovingInputStreamTester.java index 73c9590..9aa3fc9 100644 --- a/test/scanner/LispCommentRemovingInputStreamTester.java +++ b/test/scanner/LispCommentRemovingInputStreamTester.java @@ -1,5 +1,6 @@ package scanner; +import static error.ErrorManager.Severity.CRITICAL; import static org.junit.Assert.*; import static testutil.TestUtilities.*; @@ -7,7 +8,6 @@ import java.io.InputStream; import org.junit.Test; -import error.ErrorManager; import scanner.LispInputStream.*; public class LispCommentRemovingInputStreamTester { @@ -188,7 +188,7 @@ public class LispCommentRemovingInputStreamTester { try { lispInputStream.unreadLastCharacter(); } catch (MaximumUnreadsExceededException e) { - assertTrue(e.getSeverity() >= ErrorManager.CRITICAL_LEVEL); + assertEquals(CRITICAL, e.getSeverity()); } } @@ -208,7 +208,7 @@ public class LispCommentRemovingInputStreamTester { try { lispInputStream.read(); } catch (UncheckedIOException e) { - assertTrue(e.getSeverity() >= ErrorManager.CRITICAL_LEVEL); + assertEquals(CRITICAL, e.getSeverity()); } } diff --git a/test/scanner/LispScannerTypeTester.java b/test/scanner/LispScannerTypeTester.java index b4cced8..7f4f8f1 100644 --- a/test/scanner/LispScannerTypeTester.java +++ b/test/scanner/LispScannerTypeTester.java @@ -1,5 +1,6 @@ package scanner; +import static error.ErrorManager.Severity.ERROR; import static org.junit.Assert.*; import static testutil.TestUtilities.createInputStreamFromString; @@ -8,7 +9,6 @@ import java.util.*; import org.junit.*; -import error.ErrorManager; import scanner.LispScanner.UnterminatedStringException; import token.*; import token.Number; @@ -56,7 +56,7 @@ public class LispScannerTypeTester { try { assertTokenTypesMatch(input); } catch (BadCharacterException e) { - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } } @@ -135,7 +135,7 @@ public class LispScannerTypeTester { try { assertTokenTypesMatch(input); } catch (LispScanner.UnterminatedStringException e) { - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } } diff --git a/test/sexpression/SExpressionTester.java b/test/sexpression/SExpressionTester.java index cc47830..daffef7 100644 --- a/test/sexpression/SExpressionTester.java +++ b/test/sexpression/SExpressionTester.java @@ -1,12 +1,12 @@ package sexpression; +import static error.ErrorManager.Severity.ERROR; import static org.junit.Assert.*; import java.math.BigInteger; import org.junit.*; -import error.ErrorManager; import function.UserDefinedFunction; import sexpression.LispNumber.InvalidNumberException; @@ -148,7 +148,7 @@ public class SExpressionTester { try { new LispNumber("a"); } catch (InvalidNumberException e) { - assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL); + assertEquals(ERROR, e.getSeverity()); } } diff --git a/test/token/TokenFactoryTester.java b/test/token/TokenFactoryTester.java index 6f24bb7..15ea8f7 100644 --- a/test/token/TokenFactoryTester.java +++ b/test/token/TokenFactoryTester.java @@ -1,10 +1,10 @@ package token; +import static error.ErrorManager.Severity.CRITICAL; import static org.junit.Assert.*; import org.junit.*; -import error.ErrorManager; import file.FilePosition; import token.TokenFactory.*; @@ -76,7 +76,7 @@ public class TokenFactoryTester { try { createToken(""); } catch (EmptyTokenTextException e) { - assertTrue(e.getSeverity() == ErrorManager.CRITICAL_LEVEL); + assertEquals(CRITICAL, e.getSeverity()); } }