Skip to content

Commit

Permalink
Add tests for arch
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Sep 9, 2023
1 parent d5ab850 commit a4a2ef1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
42 changes: 42 additions & 0 deletions arch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"testing"

"github.com/oalders/is/ops"
"github.com/oalders/is/types"
"github.com/stretchr/testify/assert"
)

func TestArchCmd(t *testing.T) {
t.Parallel()
type ArchTest struct {
Cmd ArchCmd
Error bool
Success bool
}

tests := []ArchTest{
{ArchCmd{ops.Eq, "zzz"}, false, false},
{ArchCmd{ops.Ne, "zzz"}, false, true},
{ArchCmd{ops.Like, "zzz"}, false, false},
{ArchCmd{ops.Unlike, "zzz"}, false, true},
}

for _, test := range tests {
ctx := types.Context{Debug: false}
err := test.Cmd.Run(&ctx)
name := fmt.Sprintf("%s %s", test.Cmd.Op, test.Cmd.Val)
if test.Error {
assert.Error(t, err, name)
} else {
assert.NoError(t, err, name)
}
if test.Success {
assert.True(t, ctx.Success, name)
} else {
assert.False(t, ctx.Success, name)
}
}
}
9 changes: 9 additions & 0 deletions known_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ func TestKnownCmd(t *testing.T) {
assert.NoError(t, err)
assert.False(t, ctx.Success, "No success")
}

{
ctx := types.Context{Debug: true}
cmd := KnownCmd{}
cmd.Arch.Attr = "arch"
err := cmd.Run(&ctx)
assert.NoError(t, err)
assert.True(t, ctx.Success, "success")
}
}
19 changes: 19 additions & 0 deletions test/arch.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats

bats_require_minimum_version 1.5.0

@test "is arch ne xxx" {
./is arch ne xxx
}

@test "is arch unlike xxx" {
./is arch unlike xxx
}

@test 'is arch like ".*"' {
./is arch like ".*"
}

@test 'is arch eq beos' {
run ! ./is arch eq beos
}
15 changes: 13 additions & 2 deletions test/known.bats
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/usr/bin/env bats

@test "is known cli" {
./is known cli version tmux
./is known cli version tmux
}

@test "is known os" {
./is known os name
./is known os name
}

@test "is known arch" {
./is known arch
}

bats_require_minimum_version 1.5.0

@test "ensure something is printed" {
run -0 ./is known arch
[ -n "${lines[0]}" ]
}

0 comments on commit a4a2ef1

Please sign in to comment.