-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
* #619 another approach to fix this issue, its command line will looks like 'sysl codegen @config_file' and config_file has the all of command flags. Actually this approach can simply all commands. * #619 update test data and test case.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -908,3 +908,19 @@ func TestTemplating(t *testing.T) { | |
assert.NoError(t, err) | ||
assert.Equal(t, string(expected), string(actual)) | ||
} | ||
|
||
func TestMain3(t *testing.T) { | ||
logger, _ := test.NewNullLogger() | ||
fs := afero.NewOsFs() | ||
|
||
assert.Equal(t, nil, main3([]string{"sysl"}, fs, logger)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ericzhang6222
Author
Contributor
|
||
|
||
assert.Error(t, main3([]string{"sysl", "codegen"}, fs, logger)) | ||
|
||
assert.Error(t, main3([]string{"sysl", "codegen", "@tests/config.txt"}, fs, logger)) | ||
|
||
assert.Error(t, main3([]string{"sysl", "codegen", "@tests/config_new.txt"}, fs, logger)) | ||
|
||
assert.Error(t, main3([]string{"sysl", "codegen", "--grammar=go.gen.g", "--transform=go.gen.sysl", "model.sysl"}, | ||
fs, logger)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package syslutil | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
func ReadCMDFlags(configPath string) ([]string, error) { | ||
var flags []string | ||
data, ferr := ioutil.ReadFile(configPath) | ||
if ferr != nil { | ||
return flags, ferr | ||
} | ||
str := string(data) | ||
flags = strings.Fields(strings.TrimSpace(str)) | ||
|
||
return flags, nil | ||
} | ||
|
||
func PopulateCMDFlagsFromFile(cmdArgs []string) ([]string, error) { | ||
if len(cmdArgs) < 3 { | ||
return nil, fmt.Errorf("command arguments are not enough") | ||
} | ||
|
||
var fileFlag string | ||
for _, flag := range cmdArgs[2:] { | ||
if strings.HasPrefix(flag, "@") { | ||
fileFlag = flag | ||
break | ||
} | ||
} | ||
|
||
flags, err := ReadCMDFlags(strings.Replace(fileFlag, "@", "", 1)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return append(cmdArgs[0:2], flags...), err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package syslutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReadCMDFlags(t *testing.T) { | ||
t.Parallel() | ||
flags, err := ReadCMDFlags("tests/config.txt") | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, 4, len(flags)) | ||
assert.Equal(t, "--grammar=go.gen.g", flags[0]) | ||
assert.Equal(t, "--transform=go.gen.sysl", flags[1]) | ||
assert.Equal(t, "model.sysl", flags[2]) | ||
assert.Equal(t, "--app-name=Test", flags[3]) | ||
} | ||
|
||
func TestPopulateCMDFlagsFromFile(t *testing.T) { | ||
t.Parallel() | ||
cmdArgs := []string{"sysl", "codegen", "@tests/config.txt"} | ||
flags, err := PopulateCMDFlagsFromFile(cmdArgs) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, 6, len(flags)) | ||
assert.Equal(t, "sysl", flags[0]) | ||
assert.Equal(t, "codegen", flags[1]) | ||
assert.Equal(t, "--grammar=go.gen.g", flags[2]) | ||
assert.Equal(t, "--transform=go.gen.sysl", flags[3]) | ||
assert.Equal(t, "model.sysl", flags[4]) | ||
assert.Equal(t, "--app-name=Test", flags[5]) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--grammar=go.gen.g --transform=go.gen.sysl model.sysl --app-name=Test |
@ericzhang6222 I'm trying to chase down and fix #705 and I've found that commenting out the line above lets tests pass.
So, I've worked out that this test needs to be refactored in some way, so that
gotestsum
worksIn order to do that I need to understand what this test is trying to validate.
Is it just trying to test that running main3 doesn't return an error?