Attempt to reproduce #154

This commit is contained in:
Neale Pickett 2021-10-20 13:10:24 -06:00
parent ce037ebca3
commit 6f1f889be7
2 changed files with 32 additions and 1 deletions

View File

@ -81,7 +81,7 @@ func (t *T) ParseArgs() (Command, error) {
default: default:
fmt.Fprintln(t.Stderr, "ERROR:", t.Args[1], "is not a valid command") fmt.Fprintln(t.Stderr, "ERROR:", t.Args[1], "is not a valid command")
usage(t.Stderr) usage(t.Stderr)
return nothing, fmt.Errorf("Invalid command") return nothing, fmt.Errorf("invalid command")
} }
if err := flags.Parse(t.Args[2:]); err != nil { if err := flags.Parse(t.Args[2:]); err != nil {

View File

@ -4,7 +4,9 @@ import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"os"
"strings" "strings"
"testing" "testing"
@ -202,3 +204,32 @@ func TestFilesystem(t *testing.T) {
t.Error("Wrong file pulled", stdout.String()) t.Error("Wrong file pulled", stdout.String())
} }
} }
func TestCwd(t *testing.T) {
testwd, err := os.Getwd()
if err != nil {
t.Error("Can't get current working directory!")
return
}
defer os.Chdir(testwd)
stdin := new(bytes.Buffer)
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
tp := T{
Stdin: stdin,
Stdout: stdout,
Stderr: stderr,
BaseFs: afero.NewOsFs(),
}
stdout.Reset()
os.Chdir("/")
if err := tp.Run(
"file",
fmt.Sprintf("-dir=%s/testdata/cat1/1", testwd),
"moo.txt",
); err != nil {
t.Error(err)
}
}