Skip to content

Commit e0f3cac

Browse files
committed
[#200] Stub out vcs/p4 command calls
- In order to be able to run p4 tests withous having p4 installed and configured
1 parent 2162ced commit e0f3cac

9 files changed

+558
-153
lines changed

src/vcs/git/git_command.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"strings"
3030
)
3131

32-
func newGitCommand() *shell.Command {
33-
return shell.NewCommand("git")
32+
func newGitCommand() shell.Command {
33+
return shell.NewCommandFunc("git")
3434
}
3535

3636
// IsGitCommandAvailable indicates if git command is available on local machine

src/vcs/p4/p4_command.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ import (
2929
"strings"
3030
)
3131

32-
func newP4Command(params ...string) *shell.Command {
33-
return shell.NewCommand("p4", params...)
32+
func init() {
33+
shell.NewCommandFunc = shell.NewCommand
34+
}
35+
36+
func newP4Command(params ...string) shell.Command {
37+
return shell.NewCommandFunc("p4", params...)
38+
}
39+
40+
func newP4CommandImpl(params ...string) *shell.CommandImpl {
41+
return shell.NewCommandImpl("p4", params...)
3442
}
3543

3644
// IsP4CommandAvailable indicates if p4 command is available on local machine
@@ -52,7 +60,7 @@ func GetP4CommandVersion() string {
5260
scanner := bufio.NewScanner(bytes.NewReader(p4Output))
5361
for scanner.Scan() {
5462
if strings.Index(scanner.Text(), "Rev.") == 0 {
55-
return strings.SplitAfter(scanner.Text(), "Rev. ")[1]
63+
return strings.Split(scanner.Text(), " ")[1]
5664
}
5765
}
5866
return ""
@@ -65,7 +73,8 @@ func GetP4UserName() string {
6573

6674
func getP4ConfigValue(variable string) string {
6775
p4Output, err := runP4Command("set", "-q", variable)
68-
if err != nil || p4Output == nil || len(p4Output) == 0 {
76+
77+
if err != nil || p4Output == nil || len(bytes.Trim(p4Output, "\r\n")) == 0 {
6978
return "not set"
7079
}
7180
scanner := bufio.NewScanner(bytes.NewReader(p4Output))
@@ -84,11 +93,11 @@ func runP4Command(params ...string) (output []byte, err error) {
8493
}
8594

8695
// tracePipedP4Command calls p4 command, pipes it to pipedTo command, and reports its output traces
87-
func tracePipedP4Command(pipedTo *shell.Command, params ...string) error {
96+
func tracePipedP4Command(pipedTo shell.Command, params ...string) error {
8897
return newP4Command().TraceAndPipe(pipedTo, params...)
8998
}
9099

91100
// runPipedP4Command calls p4 command, pipes it to pipedTo command, and reports its output traces
92-
func runPipedP4Command(pipedTo *shell.Command, params ...string) (output []byte, err error) {
101+
func runPipedP4Command(pipedTo shell.Command, params ...string) (output []byte, err error) {
93102
return newP4Command().RunAndPipe(pipedTo, params...)
94103
}

0 commit comments

Comments
 (0)