add ExpectLines helper

This commit is contained in:
vilmibm 2020-03-20 16:10:32 -05:00
parent deb7ee6aa4
commit ff96f48479
4 changed files with 48 additions and 98 deletions

View file

@ -316,18 +316,11 @@ func TestIssueView_preview(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`ix of coins`),
regexp.MustCompile(`opened by marseilles. 9 comments. \(tarot\)`),
regexp.MustCompile(`bold story`),
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"ix of coins",
`opened by marseilles. 9 comments. \(tarot\)`,
"bold story",
"View this issue on GitHub: https://github.com/OWNER/REPO/issues/123")
}
func TestIssueView_previewWithEmptyBody(t *testing.T) {
@ -362,17 +355,10 @@ func TestIssueView_previewWithEmptyBody(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`ix of coins`),
regexp.MustCompile(`opened by marseilles. 9 comments. \(tarot\)`),
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"ix of coins",
`opened by marseilles. 9 comments. \(tarot\)`,
"View this issue on GitHub: https://github.com/OWNER/REPO/issues/123")
}
func TestIssueView_notFound(t *testing.T) {

View file

@ -416,18 +416,11 @@ func TestPRView_preview(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Blueberries are from a fork`),
regexp.MustCompile(`nobody wants to merge 12 commits into master from blueberries`),
regexp.MustCompile(`blueberries taste good`),
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Blueberries are from a fork",
"nobody wants to merge 12 commits into master from blueberries",
"blueberries taste good",
"View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12")
}
func TestPRView_previewCurrentBranch(t *testing.T) {
@ -451,18 +444,11 @@ func TestPRView_previewCurrentBranch(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Blueberries are a good fruit`),
regexp.MustCompile(`nobody wants to merge 8 commits into master from blueberries`),
regexp.MustCompile(`blueberries taste good`),
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Blueberries are a good fruit",
"nobody wants to merge 8 commits into master from blueberries",
"blueberries taste good",
"View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10")
}
func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
@ -486,17 +472,10 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Blueberries are a good fruit`),
regexp.MustCompile(`nobody wants to merge 8 commits into master from blueberries`),
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Blueberries are a good fruit",
"nobody wants to merge 8 commits into master from blueberries",
"View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10")
}
func TestPRView_currentBranch(t *testing.T) {

View file

@ -137,16 +137,9 @@ func TestRepoFork_in_parent_yes(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Created fork someone/REPO`),
regexp.MustCompile(`Remote added at fork`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Created fork someone/REPO",
"Remote added at fork")
}
func TestRepoFork_outside_yes(t *testing.T) {
@ -169,16 +162,9 @@ func TestRepoFork_outside_yes(t *testing.T) {
eq(t, strings.Join(seenCmd.Args, " "), "git clone https://github.com/someone/repo.git")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Created fork someone/REPO`),
regexp.MustCompile(`Cloned fork`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Created fork someone/REPO",
"Cloned fork")
}
func TestRepoFork_outside_survey_yes(t *testing.T) {
@ -208,16 +194,9 @@ func TestRepoFork_outside_survey_yes(t *testing.T) {
eq(t, strings.Join(seenCmd.Args, " "), "git clone https://github.com/someone/repo.git")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Created fork someone/REPO`),
regexp.MustCompile(`Cloned fork`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Created fork someone/REPO",
"Cloned fork")
}
func TestRepoFork_outside_survey_no(t *testing.T) {
@ -290,16 +269,9 @@ func TestRepoFork_in_parent_survey_yes(t *testing.T) {
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`Created fork someone/REPO`),
regexp.MustCompile(`Remote added at fork`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
test.ExpectLines(t, output.String(),
"Created fork someone/REPO",
"Remote added at fork")
}
func TestRepoFork_in_parent_survey_no(t *testing.T) {

View file

@ -6,6 +6,8 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"testing"
)
// OutputStub implements a simple utils.Runnable
@ -74,3 +76,14 @@ func UseTempGitRepo() *TempGitRepo {
return &TempGitRepo{Remote: remotePath, TearDown: tearDown}
}
func ExpectLines(t *testing.T, output string, lines ...string) {
var r *regexp.Regexp
for _, l := range lines {
r = regexp.MustCompile(l)
if !r.MatchString(output) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
}