From 1b307dc52dcd3c75af6944313a0f56f96495ab40 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 8 Nov 2025 00:17:42 -0500 Subject: [PATCH] Fixes for the new tested content. --- tested/cat/cat_test.go | 12 ++++++++---- tested/cat/go.mod | 8 -------- tested/cat/go.sum | 10 ---------- tested/cat/main.go | 2 -- tested/od/od_test.go | 2 +- tr/main.go | 6 +++--- uniq/main.go | 2 +- 7 files changed, 13 insertions(+), 29 deletions(-) diff --git a/tested/cat/cat_test.go b/tested/cat/cat_test.go index f3db0dd..4a46a8a 100644 --- a/tested/cat/cat_test.go +++ b/tested/cat/cat_test.go @@ -2,7 +2,6 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" "os" ) @@ -14,11 +13,14 @@ func WithArgs(args []string, test func ()) { } func TestParseOpts(t *testing.T) { - args := []string{"cat.exe", "-n", "main.go"} + args := []string{"cat", "-n", "main.go"} WithArgs(args, func () { opts := ParseOpts() - assert.Equal(t, opts.Number, true, "-n didn't work") + + if opts.Number != true { + t.Errorf("opts.Number should be true, not: %v", opts.Number) + } }) /* @@ -26,7 +28,9 @@ func TestParseOpts(t *testing.T) { args = []string{"cat.exe", "-s", "main.go"} WithArgs(args, func () { opts := ParseOpts() - assert.Equal(t, opts.Squeeze, true, "-s didn't work") + if opts.Number != true { + t.Errorf("opts.Number should be true, not: %v", opts.Number) + } }) */ } diff --git a/tested/cat/go.mod b/tested/cat/go.mod index 6c3a0f7..59745c3 100644 --- a/tested/cat/go.mod +++ b/tested/cat/go.mod @@ -1,11 +1,3 @@ module lcthw.dev/go/go-coreutils/cat go 1.24.2 - -require github.com/stretchr/testify v1.11.1 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/tested/cat/go.sum b/tested/cat/go.sum index c4c1710..e69de29 100644 --- a/tested/cat/go.sum +++ b/tested/cat/go.sum @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tested/cat/main.go b/tested/cat/main.go index fc6686b..6519953 100644 --- a/tested/cat/main.go +++ b/tested/cat/main.go @@ -17,8 +17,6 @@ type Opts struct { func ParseOpts() (Opts) { var opts Opts - fmt.Println("args:", os.Args) - flag.BoolVar(&opts.Number, "n", false, "Number all nonempty output lines, starting with 1") flag.BoolVar(&opts.Squeeze, "s", false, "Suppress repeated adjacent blank lines") flag.Parse() diff --git a/tested/od/od_test.go b/tested/od/od_test.go index db0aa10..69a3a0e 100644 --- a/tested/od/od_test.go +++ b/tested/od/od_test.go @@ -10,7 +10,7 @@ func TestParseOpts(t *testing.T) { opts := ParseOpts(args) assert.Equal(t, opts.Hex, true, "-x didn't work") - // This fails because flag can't be run more than once + // now we can test as much as we want args = []string{"cat.exe", "-o", "main.go"} opts = ParseOpts(args) assert.Equal(t, opts.Octal, true, "-o didn't work") diff --git a/tr/main.go b/tr/main.go index 677811e..2fedc06 100644 --- a/tr/main.go +++ b/tr/main.go @@ -1,12 +1,12 @@ package main import ( - "flag" - "os" "bufio" - "strings" + "flag" "fmt" "log" + "os" + "strings" ) type Opts struct { diff --git a/uniq/main.go b/uniq/main.go index 1b887ec..97636da 100644 --- a/uniq/main.go +++ b/uniq/main.go @@ -17,7 +17,7 @@ func ParseOpts() Opts { var opts Opts flag.BoolVar(&opts.IgnoreCase, "i", false, "ignore case") - flag.BoolVar(&opts.Count, "c", false, "count occurence") + flag.BoolVar(&opts.Count, "c", false, "count occurrence") flag.Parse() return opts