Git Product home page Git Product logo

Comments (4)

warpfork avatar warpfork commented on May 31, 2024

The examples from the slides deck are actually links 😁 -- you can follow them from https://slides.com/warpfork/testmark#/9/1 , and the couple of pages below that (hit spacebar to progress to next-slide).

Here are some of those links extracted:

from go-testmark.

warpfork avatar warpfork commented on May 31, 2024

I also recently saw someone start using line numbers from testmark hunks as part of their test failure messages, which seems neat: ipld/go-datalark@82b8d0f

... there's a lot of other testmark example setup in there, too, which might be another fun source to look at. Some of it is very cool, because that project involves an interpreted language, so it's actually got "executable" script hunks and their outputs paired together as tests!

from go-testmark.

warpfork avatar warpfork commented on May 31, 2024

Come to think of it, you could actually use the testexec extension package in this same repo as a good example -- if I had to highlight some lines to focus on, probably these in particular show the heart of it:

// Prepare output buffers.
var stdout, stderr io.Writer
if _, exists := data.Children["output"]; exists {
stdout = &bytes.Buffer{}
stderr = stdout
if _, exists := data.Children["stdout"]; exists {
t.Errorf("testexec entry %q shouldn't contain 'stdout' hunk if it also specifies a unified 'output' hunk", data.Name)
}
if _, exists := data.Children["stderr"]; exists {
t.Errorf("testexec entry %q shouldn't contain 'stderr' hunk if it also specifies a unified 'output' hunk", data.Name)
}
}
if _, exists := data.Children["stdout"]; exists {
stdout = &bytes.Buffer{}
}
if _, exists := data.Children["stderr"]; exists {
stderr = &bytes.Buffer{}
}
var exitcode int
// Prepare an input buffer, if applicable.
var stdin io.Reader
if ent := data.Children["input"]; ent != nil {
stdin = bytes.NewReader(ent.Hunk.Body)
} else {
stdin = bytes.NewReader(nil)
}
// Do the thing.
switch {
case sequenceMode:
exitcode = tcfg.doSequence(t, sequenceHunk.Hunk, stdin, stdout, stderr)
case scriptMode:
exitcode = tcfg.doScript(t, scriptHunk.Hunk, stdin, stdout, stderr)
}
// Okay, comparisons time.
// Or, regen time!
if ent, exists := data.Children["output"]; exists {
bs := stdout.(*bytes.Buffer).Bytes()
if *testmark.Regen {
tcfg.Patches.AppendPatchIfBodyDiffers(*ent.Hunk, bs)
} else {
t.Run("check-combined-output", func(t *testing.T) {
tcfg.AssertFn(t, string(bs), string(ent.Hunk.Body))
})
}
}
if ent, exists := data.Children["stdout"]; exists {
bs := stdout.(*bytes.Buffer).Bytes()
if *testmark.Regen {
tcfg.Patches.AppendPatchIfBodyDiffers(*ent.Hunk, bs)
} else {
t.Run("check-stdout", func(t *testing.T) {
tcfg.AssertFn(t, string(bs), string(ent.Hunk.Body))
})
}
}
if ent, exists := data.Children["stderr"]; exists {
bs := stderr.(*bytes.Buffer).Bytes()
if *testmark.Regen {
tcfg.Patches.AppendPatchIfBodyDiffers(*ent.Hunk, bs)
} else {
t.Run("check-stderr", func(t *testing.T) {
tcfg.AssertFn(t, string(bs), string(ent.Hunk.Body))
})
}
}
t.Run("check-exitcode", func(t *testing.T) {
if ent, exists := data.Children["exitcode"]; exists {
if *testmark.Regen {
tcfg.Patches.AppendPatchIfBodyDiffers(*ent.Hunk, []byte(strconv.Itoa(exitcode)))
} else {
tcfg.AssertFn(t, strconv.Itoa(exitcode), strings.TrimSpace(string(ent.Hunk.Body)))
}
} else {
tcfg.AssertFn(t, strconv.Itoa(exitcode), "0")
}
})

from go-testmark.

warpfork avatar warpfork commented on May 31, 2024

Hope these examples help!

If you end up producing more, please comment with them! It would be a joy to see :)

from go-testmark.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.