Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Proposal for a unified testing API for Golo #438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/golo/tests.golo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module gololang.testing.Utils


struct Test = { description, test }
struct Suite = { description, tests }
struct TestResult = { description, result }

function run = |suites| {
java.lang.System.exit(defaultReporter(defaultRunner(suites)))
}

let defaultRunner = asFunctionalInterface(gololang.testing.TestRunner.class, |suites| -> list[
[desc, match {
when isClosure(test) then trying(test)
otherwise defaultRunner(test)
}]
foreach desc, test in suites
])


let defaultReporter = asFunctionalInterface(gololang.testing.TestReporter.class, |results| {
var err = 0
foreach desc, result in results {
if result oftype gololang.error.Result.class {
print(desc + " " + result: either(
|v| -> "OK",
|e| -> "FAIL: " + e: message()))
if result: isError() {
err = err + 1
}
} else {
println("# " + desc)
err = err + defaultResult(result)
}
}
return err
}

let defaultResult = |result| -> 1
11 changes: 11 additions & 0 deletions src/main/java/gololang/testing/TestExtractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gololang.testing;

import gololang.Tuple;

import java.nio.file.Path;

@FunctionalInterface
public interface TestExtractor {

Tuple extract(Path path);
}
9 changes: 9 additions & 0 deletions src/main/java/gololang/testing/TestReporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gololang.testing;

import gololang.Tuple;

@FunctionalInterface
public interface TestReporter {

int report(Tuple results);
}
9 changes: 9 additions & 0 deletions src/main/java/gololang/testing/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gololang.testing;

import gololang.Tuple;

@FunctionalInterface
public interface TestRunner {

Tuple run(Tuple suites);
}