github.com/ccccaoqing/test@v0.0.0-20220510085219-3985d23445c0/src/os/exec/lp_test.go (about)

     1  // Copyright 2011 The Go 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 exec
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  var nonExistentPaths = []string{
    12  	"some-non-existent-path",
    13  	"non-existent-path/slashed",
    14  }
    15  
    16  func TestLookPathNotFound(t *testing.T) {
    17  	for _, name := range nonExistentPaths {
    18  		path, err := LookPath(name)
    19  		if err == nil {
    20  			t.Fatalf("LookPath found %q in $PATH", name)
    21  		}
    22  		if path != "" {
    23  			t.Fatalf("LookPath path == %q when err != nil", path)
    24  		}
    25  		perr, ok := err.(*Error)
    26  		if !ok {
    27  			t.Fatal("LookPath error is not an exec.Error")
    28  		}
    29  		if perr.Name != name {
    30  			t.Fatalf("want Error name %q, got %q", name, perr.Name)
    31  		}
    32  	}
    33  }