github.com/gogf/gf/v2@v2.7.4/os/gproc/gproc_z_unit_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package gproc_test 10 11 import ( 12 "testing" 13 14 "github.com/gogf/gf/v2/os/gctx" 15 "github.com/gogf/gf/v2/os/gproc" 16 "github.com/gogf/gf/v2/test/gtest" 17 ) 18 19 func Test_ShellExec(t *testing.T) { 20 gtest.C(t, func(t *gtest.T) { 21 s, err := gproc.ShellExec(gctx.New(), `echo 123`) 22 t.AssertNil(err) 23 t.Assert(s, "123\n") 24 }) 25 // error 26 gtest.C(t, func(t *gtest.T) { 27 _, err := gproc.ShellExec(gctx.New(), `NoneExistCommandCall`) 28 t.AssertNE(err, nil) 29 }) 30 }