2019-09-05 11:38:36 +08:00
|
|
|
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
// go test *.go -bench=".*" -benchmem
|
|
|
|
|
|
|
|
package gcmd_test
|
|
|
|
|
|
|
|
import (
|
2019-09-05 15:16:25 +08:00
|
|
|
"os"
|
2019-09-05 11:38:36 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
|
"github.com/gogf/gf/os/gcmd"
|
|
|
|
|
|
|
|
"github.com/gogf/gf/test/gtest"
|
|
|
|
)
|
|
|
|
|
2019-09-05 15:16:25 +08:00
|
|
|
func Test_Default(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2019-09-05 15:16:25 +08:00
|
|
|
os.Args = []string{"gf", "--force", "remove", "-fq", "-p=www", "path", "-n", "root"}
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(len(gcmd.GetArgAll()), 4)
|
|
|
|
t.Assert(gcmd.GetArg(1), "remove")
|
|
|
|
t.Assert(gcmd.GetArg(100, "test"), "test")
|
|
|
|
t.Assert(gcmd.GetOpt("n"), "")
|
|
|
|
t.Assert(gcmd.ContainsOpt("p"), true)
|
|
|
|
t.Assert(gcmd.ContainsOpt("n"), true)
|
|
|
|
t.Assert(gcmd.ContainsOpt("none"), false)
|
|
|
|
t.Assert(gcmd.GetOpt("none", "value"), "value")
|
2019-09-05 15:16:25 +08:00
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-05 11:38:36 +08:00
|
|
|
func Test_BuildOptions(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2019-09-05 11:38:36 +08:00
|
|
|
s := gcmd.BuildOptions(g.MapStrStr{
|
|
|
|
"n": "john",
|
|
|
|
})
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(s, "-n=john")
|
2019-09-05 11:38:36 +08:00
|
|
|
})
|
|
|
|
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2019-09-05 11:38:36 +08:00
|
|
|
s := gcmd.BuildOptions(g.MapStrStr{
|
|
|
|
"n": "john",
|
|
|
|
}, "-test")
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(s, "-testn=john")
|
2019-09-05 11:38:36 +08:00
|
|
|
})
|
|
|
|
}
|