Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Add YAML() for generating YAML blocks #7

Merged
merged 2 commits into from
Dec 3, 2017
Merged

Add YAML() for generating YAML blocks #7

merged 2 commits into from
Dec 3, 2017

Conversation

wking
Copy link
Collaborator

@wking wking commented Nov 30, 2017

Docs here. I've used Go's JSON serializer to avoid external dependencies, since JSON is a subset of YAML. 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 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

I'll work up a prove ticket once I can find out where to file it. In the mean time, would you consider switching to node-tap for this project?

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/
@wking
Copy link
Collaborator Author

wking commented Nov 30, 2017

There's an existing prove bug here. If we want to use prove before that is fixed, we could probably do so by using a YAML marshaller instead of the JSON marshaller. Personally, I prefer switching to node-tap over adding a non-stdlib Go requirement, but I could see that going either way depending on how involved with prove a given tap-go consumer is.

@mndrix
Copy link
Owner

mndrix commented Dec 1, 2017

I'm hesitant to move away from prove since many Unix-like systems have it installed by default as part of their Perl installation. If an external dependency is absolutely necessary, I'd prefer a Go dependency since go get makes those easy to deal with on all platforms.

Having said that, is it possible to configure JSON output into a format that prove can parse? Maybe by skipping indentation and placing it all on one line?

@wking
Copy link
Collaborator Author

wking commented Dec 1, 2017

Having said that, is it possible to configure JSON output into a format that prove can parse? Maybe by skipping indentation and placing it all on one line?

I tried that, and it didn't work either. And there are no Go consumers listed here. So should I add a Go YAML dependency?

@wking
Copy link
Collaborator Author

wking commented Dec 1, 2017

Ah, I'll put it behing an optional build flag, so whoever's compiling can choose.

So folks who are comfortable with the additional dependency can get
prove-compatible output.  Michael wants to stick with prove for tap-go
because it is widely installed [1], but folks using node-tap or other
consumers that can handle the JSON subset of YAML probably don't want
the external dependency.  Folks who want yaml.v2 can enable the yaml
build tag [2].  Folks who are ok with JSON don't have to set any build
tags.

The go-yaml dependency is the only Go producer listed in [3].  There
may be others, I haven't checked.

The Makefile changes include new uses of wildcards [4] to pick up
test/%/*.go siblings.  And I'm using the stem variable $* [5] in the
rule to pick up the whole test package (and not just main.go).

I'm not sure how Michael wants vendoring to work.  For the moment,
I've softened the 'GOPATH =' to a 'GOPATH ?=' and installed the
package in my local GOPATH.  It's possible that we want to stick with
'GOPATH =' and drop the package under gopath/ (via a Git submodule?).

[1]: mndrix#7 (comment)
[2]: https://golang.org/pkg/go/build/#hdr-Build_Constraints
[3]: http://yaml.org/
[4]: https://www.gnu.org/software/make/manual/html_node/Wildcard-Examples.html
[5]: https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
@wking
Copy link
Collaborator Author

wking commented Dec 1, 2017

Ok, I've pushed 4656fa9 with a yaml build tag to conditionally use gopkg.in/yaml.v2. It looks reasonable to me, but I'm not sure how you want to handle vendoring the new dependency. I've currently softened GOPATH = to GOPATH ?= in the Makefile (so we can pull the package from a local GOPATH). But I can vendor it under gopath/ (via a Git submodule?) if you'd rather go that route.

@mndrix
Copy link
Owner

mndrix commented Dec 2, 2017

Good idea to use a build flag. I think it's fine to use a local GOPATH for the new dependency.

I'm traveling for the next few months and won't have as much time to review and test code as usual. I'm also not actively using tap-go at the moment, so you're probably in a better position right now to judge these contributions. Your contributions so far have been good, so I've added you as a collaborator on this repository. Feel free to merge this pull request (and others) when you feel that they're ready for general consumption. I'll offer feedback as opportunity permits.

@wking wking merged commit 4656fa9 into mndrix:master Dec 3, 2017
@wking wking deleted the yaml branch December 3, 2017 23:09
@wking
Copy link
Collaborator Author

wking commented Dec 3, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants