Skip to content

Commit

Permalink
2.1. 0 Fix misc bugs and add support for printing arrays in failure m…
Browse files Browse the repository at this point in the history
…essages
  • Loading branch information
joshuacc committed Nov 30, 2022
1 parent 15ee4d0 commit c1304bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
48 changes: 41 additions & 7 deletions AutoHotUnit.ahk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#SingleInstance Force
; #Warn All, StdOut
#Warn All, StdOut
FileEncoding("UTF-8")

global ahu := AutoHotUnitManager(AutoHotUnitCLIReporter())
Expand Down Expand Up @@ -69,7 +69,7 @@ class AutoHotUnitManager {
try {
suiteInstance.beforeAll()
} catch Error as e {
this.reporter.onTestResult("beforeAll", "failed", e)
this.reporter.onTestResult("beforeAll", "failed", "", e)
continue
}

Expand Down Expand Up @@ -103,7 +103,7 @@ class AutoHotUnitManager {
try {
suiteInstance.afterAll()
} catch Error as e {
this.reporter.onTestResult("afterEach", "failed", e)
this.reporter.onTestResult("afterAll", "failed", "", e)
continue
}

Expand Down Expand Up @@ -139,7 +139,7 @@ class AutoHotUnitCLIReporter {

onTestResult(testName, status, where, error) {
if (status != "passed" && status != "failed") {
throw "Invalid status: " . status
throw Error("Invalid status: " . status)
}

prefix := this.green . "."
Expand Down Expand Up @@ -178,9 +178,43 @@ class AutoHotUnitCLIReporter {
}

class AutoHotUnitAsserter {
static deepEqual(actual, expected) {
if (actual is Array && expected is Array) {
if (actual.Length != expected.Length) {
return false
}

for i, actualItem in actual {
if (!this.deepEqual(actualItem, expected[i])) {
return false
}
}

return true
}

return actual == expected
}

static getPrintableValue(value) {
if (value is Array) {
str := "["
for i, item in value {
if (i > 1) {
str .= ", "
}
str .= this.getPrintableValue(item)
}
str .= "]"
return str
}

return value
}

equal(actual, expected) {
if (actual != expected) {
throw Error("Assertion failed: " . actual . " != " . expected)
if (!AutoHotUnitAsserter.deepEqual(actual, expected)) {
throw Error("Assertion failed: " . AutoHotUnitAsserter.getPrintableValue(actual) . " != " . AutoHotUnitAsserter.getPrintableValue(expected))
}
}

Expand Down Expand Up @@ -215,7 +249,7 @@ class AutoHotUnitAsserter {
}

fail(message) {
throw "Assertion failed: " . message
throw Error("Assertion failed: " . message)
}

isAbove(actual, expected) {
Expand Down
2 changes: 1 addition & 1 deletion ahkpm.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0",
"version": "2.1.0",
"description": "A unit testing framework for AutoHotkey",
"repository": "https://github.com/joshuacc/AutoHotUnit",
"website": "https://github.com/joshuacc/AutoHotUnit",
Expand Down

0 comments on commit c1304bc

Please sign in to comment.