Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Split up TapReporter function into two functions
Browse files Browse the repository at this point in the history
Suggested by @tombentley.
  • Loading branch information
lucaswerkmeister committed Apr 29, 2016
1 parent b53015d commit f60ed7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
19 changes: 5 additions & 14 deletions source/ceylon/test/engine/internal/Runner.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,15 @@ shared class Runner() {
if (exists socket) {
testListeners.add(TestEventPublisher(socket.write));
} else if (exists tap = options.tap) {
void write(String? line);
if (tap == "-") {
write = void(String? line) {
if (exists line) {
print(line);
}
};
testListeners.add(TapReporter());
} else {
value writer = FileWriter(tap);
write = void(String? line) {
if (exists line) {
writer.writeLine(line);
} else {
writer.destroy(null);
}
};
testListeners.add(TapReporter {
void write(String line) => writer.writeLine(line);
void close() => writer.destroy(null);
});
}
testListeners.add(TapReporter(write));
} else {
testListeners.add(TestLoggingListener(options.colorReset, options.colorGreen, options.colorRed));
}
Expand Down
12 changes: 6 additions & 6 deletions source/ceylon/test/reporter/TapReporter.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ import ceylon.test.engine {
at com.redhat.ceylon.launcher.Launcher.main(Launcher.java:21)
...
~~~"
shared class TapReporter(write) satisfies TestListener {
shared class TapReporter(write = print, close = noop) satisfies TestListener {

"A function that logs the given line, for example by writing to standard output.
The function is called with a [[null]] argument at the end to signal the end of reporting;
this may be used to close an underlying stream if necessary."
void write(String? line);
"A function that logs the given line, for example [[print]]."
void write(String line);
"A function that is called at the end of reporting and may, for example, close an underlying stream."
void close();

variable Integer count = 1;

Expand All @@ -123,7 +123,7 @@ shared class TapReporter(write) satisfies TestListener {

shared actual void testRunFinished(TestRunFinishedEvent event) {
write("1..`` count - 1 ``");
write(null); // close stream
close();
}

shared actual void testFinished(TestFinishedEvent event) => writeProtocol(event);
Expand Down

0 comments on commit f60ed7b

Please sign in to comment.