This is an education project that attempts to reimplement the GNU coreutils in Go. You can find the full manual here:
https://www.gnu.org/software/coreutils/manual/coreutils.html
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
648 B
32 lines
648 B
package main
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/stretchr/testify/assert"
|
|
"os"
|
|
)
|
|
|
|
func WithArgs(args []string, test func ()) {
|
|
old_args := os.Args
|
|
defer (func() { os.Args = old_args })()
|
|
os.Args = args
|
|
test()
|
|
}
|
|
|
|
func TestParseOpts(t *testing.T) {
|
|
args := []string{"cat.exe", "-n", "main.go"}
|
|
|
|
WithArgs(args, func () {
|
|
opts := ParseOpts()
|
|
assert.Equal(t, opts.Number, true, "-n didn't work")
|
|
})
|
|
|
|
/*
|
|
// This fails because flag can't be run more than once
|
|
args = []string{"cat.exe", "-s", "main.go"}
|
|
WithArgs(args, func () {
|
|
opts := ParseOpts()
|
|
assert.Equal(t, opts.Squeeze, true, "-s didn't work")
|
|
})
|
|
*/
|
|
}
|
|
|