Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // 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 Nicolaou | b6cd396 | 2015-03-08 22:57:03 -0700 | [diff] [blame] | 5 | package exec_test |
| 6 | |
| 7 | import ( |
| 8 | "bufio" |
| 9 | "fmt" |
| 10 | "os/exec" |
| 11 | "regexp" |
| 12 | "testing" |
| 13 | "time" |
| 14 | |
Mike Burrows | ccca2f4 | 2015-03-27 13:57:29 -0700 | [diff] [blame] | 15 | "v.io/v23/verror" |
Cosmos Nicolaou | b6cd396 | 2015-03-08 22:57:03 -0700 | [diff] [blame] | 16 | vexec "v.io/x/ref/lib/exec" |
Cosmos Nicolaou | b6cd396 | 2015-03-08 22:57:03 -0700 | [diff] [blame] | 17 | ) |
| 18 | |
| 19 | func 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 Burrows | ccca2f4 | 2015-03-27 13:57:29 -0700 | [diff] [blame] | 26 | if got, want := ph.WaitForReady(time.Minute), vexec.ErrNotUsingProtocol.ID; verror.ErrorID(got) != want { |
Cosmos Nicolaou | b6cd396 | 2015-03-08 22:57:03 -0700 | [diff] [blame] | 27 | t.Fatalf("got %v, want %v", got, want) |
| 28 | } |
Todd Wang | 644ec62 | 2015-04-06 17:46:44 -0700 | [diff] [blame] | 29 | re := regexp.MustCompile(fmt.Sprintf(".*%s=.*", vexec.ExecVersionVariable)) |
Cosmos Nicolaou | b6cd396 | 2015-03-08 22:57:03 -0700 | [diff] [blame] | 30 | scanner := bufio.NewScanner(stdout) |
| 31 | for scanner.Scan() { |
| 32 | if re.MatchString(scanner.Text()) { |
Todd Wang | 644ec62 | 2015-04-06 17:46:44 -0700 | [diff] [blame] | 33 | t.Fatalf("%s passed to child", vexec.ExecVersionVariable) |
Cosmos Nicolaou | b6cd396 | 2015-03-08 22:57:03 -0700 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | } |