Created
April 1, 2015 10:06
-
-
Save def-/52cacd2a6e527b93ff42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest, nre, optional_t | |
type ErrorType* = enum stacktrace, phperror, other | |
type Error* = object | |
lines*: string | |
etype*: ErrorType | |
proc categorizeError*(e: Error): Error = | |
if e.lines.find(re"stack trace:").isSome: | |
Error(lines: e.lines, etype: ErrorType.stacktrace) | |
else: | |
Error(lines: e.lines, etype: ErrorType.phperror) | |
suite "categorizeError": | |
test "stacktrace": | |
var input = Error(lines: "lolol o lololo l stack trace: rcoeucr hoeruch") | |
var result = categorizeError(input) | |
check(result.etype == ErrorType.stacktrace) | |
test "php error": | |
var input = Error(lines: "5496 FastCGI sent in stderr: \"PHP message: PHP Warning: array_key_exists(") | |
var result = categorizeError(input) | |
check(result.etype == ErrorType.phperror) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment