Skip to content

Commit 7e9d1ac

Browse files
committed
Add YAML() for generating YAML blocks
Docs in [1]. I've used Go's JSON serializer to avoid external dependencies, since JSON is a subset of YAML [2]. Prove is currently choking on the results: $ prove test/yaml/test test/yaml/test .. Failed 1/2 subtests Test Summary Report ------------------- test/yaml/test (Wstat: (none) Tests: 1 Failed: 0) Parse errors: Unsupported YAMLish syntax: '{' at /usr/lib64/perl5/5.22.3/TAP/Parser/YAMLish/Reader.pm line 101. Bad plan. You planned 2 tests but ran 1. Files=1, Tests=1, 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) Result: FAIL $ prove --version TAP::Harness v3.35_01 and Perl v5.22.3 but node-tap [3] parses it fine: $ tap test/yaml/test test/yaml/test ........................................ 2/2 total ................................................. 2/2 2 passing (32.15ms) ok $ tap --version 11.0.0 [1]: https://testanything.org/tap-version-13-specification.html#yaml-blocks [2]: http://www.yaml.org/spec/1.2/spec.html $ curl -s http://www.yaml.org/spec/1.2/spec.html | grep -B1 JSON | head -n2 The primary objective of this revision is to bring YAML into compliance with JSON as an official subset. YAML 1.2 is compatible with 1.1 for [3]: http://www.node-tap.org/
1 parent 5c04ecb commit 7e9d1ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

util/tap.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package tap // import "github.com/mndrix/tap-go"
2222

2323
import (
24+
"encoding/json"
2425
"fmt"
2526
"io"
2627
"os"
@@ -151,3 +152,15 @@ func (t *T) Diagnostic(message string) {
151152
func (t *T) Diagnosticf(format string, a ...interface{}) {
152153
t.printf("# "+escapeNewlines(format)+"\n", a...)
153154
}
155+
156+
// YAML generates a YAML block from the message.
157+
func (t *T) YAML(message interface{}) error {
158+
bytes, err := json.MarshalIndent(message, " ", " ")
159+
if err != nil {
160+
return err
161+
}
162+
t.printf(" ---\n ")
163+
t.printf(string(bytes))
164+
t.printf("\n ...\n")
165+
return nil
166+
}

0 commit comments

Comments
 (0)