github.com/vanadium-archive/go.jiri@v0.0.0-20160715023856-abfb8b131290/cmd/jiri/which_test.go (about) 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 5 package main 6 7 import ( 8 "fmt" 9 "path/filepath" 10 "testing" 11 12 "v.io/x/lib/gosh" 13 ) 14 15 func TestWhich(t *testing.T) { 16 sh := gosh.NewShell(t) 17 sh.PropagateChildOutput = true 18 defer sh.Cleanup() 19 20 jiriBinary := gosh.BuildGoPkg(sh, sh.MakeTempDir(), "v.io/jiri/cmd/jiri") 21 stdout, stderr := sh.Cmd(jiriBinary, []string{"which"}...).StdoutStderr() 22 if got, want := stdout, fmt.Sprintf("# binary\n%s\n", jiriBinary); got != want { 23 t.Errorf("stdout got %q, want %q", got, want) 24 } 25 if got, want := stderr, ""; got != want { 26 t.Errorf("stderr got %q, want %q", got, want) 27 } 28 } 29 30 // TestWhichScript tests the behavior of "jiri which" for the shim script. 31 func TestWhichScript(t *testing.T) { 32 sh := gosh.NewShell(t) 33 sh.PropagateChildOutput = true 34 defer sh.Cleanup() 35 36 jiriScript, err := filepath.Abs("../../scripts/jiri") 37 if err != nil { 38 t.Fatalf("couldn't determine absolute path to jiri script") 39 } 40 stdout, stderr := sh.Cmd(jiriScript, "which").StdoutStderr() 41 if got, want := stdout, fmt.Sprintf("# script\n%s\n", jiriScript); got != want { 42 t.Errorf("stdout got %q, want %q", got, want) 43 } 44 if got, want := stderr, ""; got != want { 45 t.Errorf("stderr got %q, want %q", got, want) 46 } 47 }