Skip to content

Commit

Permalink
fix!: lines should be empty in case of no output. closes #157
Browse files Browse the repository at this point in the history
Signed-off-by: Joke de Buhr <[email protected]>
  • Loading branch information
joke committed Mar 12, 2024
1 parent c0328ed commit 3ea0a84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.joke.test

import io.github.joke.spockoutputcapture.CapturedOutput
import io.github.joke.spockoutputcapture.OutputCapture
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Stepwise

@Stepwise
class EmptyLogs extends Specification {

@Shared @OutputCapture CapturedOutput globalLogs
@OutputCapture CapturedOutput localLogs

def 'empty logs'() {
expect:
globalLogs.lines.empty
localLogs.lines.empty
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package io.github.joke.spockoutputcapture;

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;

public class CapturedOutputImpl implements CapturedOutput {

private static final Pattern NEWLINES = Pattern.compile("(\\r\\n|\\n|\\r)");

private final StringBuffer buffer = new StringBuffer();

@Override
Expand All @@ -15,7 +20,8 @@ public String toString() {

@Override
public List<String> getLines() {
return asList(buffer.toString().split("(\\r\\n|\\n|\\r)"));
return NEWLINES.splitAsStream(buffer.toString())
.collect(toList());
}

@Override
Expand Down

0 comments on commit 3ea0a84

Please sign in to comment.