blob: ba0444b62440b8f8579e591a16865b57d95c6ed7 [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Cosmos Nicolaoub6cd3962015-03-08 22:57:03 -07005package exec_test
6
7import (
8 "bufio"
9 "fmt"
10 "os/exec"
11 "regexp"
12 "testing"
13 "time"
14
Mike Burrowsccca2f42015-03-27 13:57:29 -070015 "v.io/v23/verror"
Cosmos Nicolaoub6cd3962015-03-08 22:57:03 -070016 vexec "v.io/x/ref/lib/exec"
Cosmos Nicolaoub6cd3962015-03-08 22:57:03 -070017)
18
19func TestNoExecProtocol(t *testing.T) {
20 cmd := exec.Command("bash", "-c", "printenv")
21 stdout, _ := cmd.StdoutPipe()
22 ph := vexec.NewParentHandle(cmd, vexec.UseExecProtocolOpt(false))
23 if err := ph.Start(); err != nil {
24 t.Fatal(err)
25 }
Mike Burrowsccca2f42015-03-27 13:57:29 -070026 if got, want := ph.WaitForReady(time.Minute), vexec.ErrNotUsingProtocol.ID; verror.ErrorID(got) != want {
Cosmos Nicolaoub6cd3962015-03-08 22:57:03 -070027 t.Fatalf("got %v, want %v", got, want)
28 }
Todd Wang644ec622015-04-06 17:46:44 -070029 re := regexp.MustCompile(fmt.Sprintf(".*%s=.*", vexec.ExecVersionVariable))
Cosmos Nicolaoub6cd3962015-03-08 22:57:03 -070030 scanner := bufio.NewScanner(stdout)
31 for scanner.Scan() {
32 if re.MatchString(scanner.Text()) {
Todd Wang644ec622015-04-06 17:46:44 -070033 t.Fatalf("%s passed to child", vexec.ExecVersionVariable)
Cosmos Nicolaoub6cd3962015-03-08 22:57:03 -070034 }
35 }
36}