Skip to content

Commit

Permalink
prepend test dir to $PATH in test for known
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Jun 6, 2024
1 parent cbb77ae commit 01989d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
33 changes: 17 additions & 16 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/stretchr/testify/assert"
)

const tmux = "./testdata/bin/tmux"

func TestCliVersion(t *testing.T) {
t.Parallel()
const command = "tmux"
t.Setenv("PATH", prependPath("testdata/bin"))

type test struct {
Cmp VersionCmp
Error bool
Expand All @@ -24,16 +24,16 @@ func TestCliVersion(t *testing.T) {

//nolint:godox
tests := []test{
{VersionCmp{tmux, ops.Ne, "1", major, minor, patch}, false, true},
{VersionCmp{command, ops.Ne, "1", major, minor, patch}, false, true},
{VersionCmp{"tmuxzzz", ops.Ne, "1", major, minor, patch}, true, false},
{VersionCmp{tmux, ops.Eq, "1", major, minor, patch}, false, false},
{VersionCmp{tmux, ops.Eq, "zzz", major, minor, patch}, true, false},
{VersionCmp{tmux, ops.Unlike, "zzz", major, minor, patch}, false, true},
{VersionCmp{tmux, ops.Like, "", major, minor, patch}, false, true}, // FIXME
{VersionCmp{tmux, ops.Like, "3.*", major, minor, patch}, false, true},
{VersionCmp{tmux, ops.Eq, "3", true, minor, patch}, false, true},
{VersionCmp{tmux, ops.Eq, "3", major, true, patch}, false, true},
{VersionCmp{tmux, ops.Eq, "0", major, minor, true}, false, true},
{VersionCmp{command, ops.Eq, "1", major, minor, patch}, false, false},
{VersionCmp{command, ops.Eq, "zzz", major, minor, patch}, true, false},
{VersionCmp{command, ops.Unlike, "zzz", major, minor, patch}, false, true},
{VersionCmp{command, ops.Like, "", major, minor, patch}, false, true}, // FIXME
{VersionCmp{command, ops.Like, "3.*", major, minor, patch}, false, true},
{VersionCmp{command, ops.Eq, "3", true, minor, patch}, false, true},
{VersionCmp{command, ops.Eq, "3", major, true, patch}, false, true},
{VersionCmp{command, ops.Eq, "0", major, minor, true}, false, true},
}

for _, test := range tests {
Expand All @@ -54,24 +54,25 @@ func TestCliVersion(t *testing.T) {
}

func TestCliAge(t *testing.T) {
t.Parallel()
t.Setenv("PATH", prependPath("testdata/bin"))
const command = "tmux"
{
ctx := types.Context{Debug: true}
cmd := CLICmd{Age: AgeCmp{tmux, ops.Gt, "1", "s"}}
cmd := CLICmd{Age: AgeCmp{command, ops.Gt, "1", "s"}}
err := cmd.Run(&ctx)
assert.NoError(t, err)
assert.True(t, ctx.Success)
}
{
ctx := types.Context{Debug: true}
cmd := CLICmd{Age: AgeCmp{tmux, ops.Lt, "100000", "days"}}
cmd := CLICmd{Age: AgeCmp{command, ops.Lt, "100000", "days"}}
err := cmd.Run(&ctx)
assert.NoError(t, err)
assert.True(t, ctx.Success)
}
{
ctx := types.Context{Debug: true}
cmd := CLICmd{Age: AgeCmp{tmux, ops.Lt, "1.1", "d"}}
cmd := CLICmd{Age: AgeCmp{command, ops.Lt, "1.1", "d"}}
err := cmd.Run(&ctx)
assert.Error(t, err)
assert.False(t, ctx.Success)
Expand Down
24 changes: 18 additions & 6 deletions known_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"os"
"path/filepath"
"runtime"
"testing"

Expand All @@ -10,9 +12,19 @@ import (
"github.com/stretchr/testify/assert"
)

func prependPath(path string) string {
wd, err := os.Getwd()
if err != nil {
panic(err)
}

return filepath.Join(wd, path) + string(os.PathListSeparator) + os.Getenv("PATH")
}

func TestKnownCmd(t *testing.T) {
t.Parallel()
const tmux = "testdata/bin/tmux"
t.Setenv("PATH", prependPath("testdata/bin"))

const command = "semver"
type testableOS struct {
Attr string
Error bool
Expand Down Expand Up @@ -55,10 +67,10 @@ func TestKnownCmd(t *testing.T) {
}
cliTests := []testableCLI{
{KnownCmd{CLI: KnownCLI{attr.Version, "gitzzz"}}, false, false},
{KnownCmd{CLI: KnownCLI{attr.Version, tmux}}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, tmux}, Major: true}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, tmux}, Minor: true}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, tmux}, Patch: true}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, command}}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, command}, Major: true}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, command}, Minor: true}, false, true},
{KnownCmd{CLI: KnownCLI{attr.Version, command}, Patch: true}, false, true},
}

for _, test := range cliTests {
Expand Down

0 comments on commit 01989d6

Please sign in to comment.