// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package exec
+package exec_test
import (
"errors"
"internal/syscall/unix"
+ "internal/testenv"
"os"
+ "os/exec"
"path/filepath"
"syscall"
"testing"
// Create a tmpfs mount.
err := syscall.Mount("tmpfs", tmp, "tmpfs", 0, "")
- if err != nil {
+ if testenv.SyscallIsNotSupported(err) {
// Usually this means lack of CAP_SYS_ADMIN, but there might be
// other reasons, especially in restricted test environments.
t.Skipf("requires ability to mount tmpfs (%v)", err)
+ } else if err != nil {
+ t.Fatalf("mount %s failed: %v", tmp, err)
}
t.Cleanup(func() {
if err := syscall.Unmount(tmp, 0); err != nil {
}
// Check that it works as expected.
- err = findExecutable(path)
+ _, err = exec.LookPath(path)
if err != nil {
t.Fatalf("findExecutable: got %v, want nil", err)
}
for {
- err = Command(path).Run()
+ err = exec.Command(path).Run()
if err == nil {
break
}
// Remount with noexec flag.
err = syscall.Mount("", tmp, "", syscall.MS_REMOUNT|syscall.MS_NOEXEC, "")
- if err != nil {
+ if testenv.SyscallIsNotSupported(err) {
+ t.Skipf("requires ability to re-mount tmpfs (%v)", err)
+ } else if err != nil {
t.Fatalf("remount %s with noexec failed: %v", tmp, err)
}
- if err := Command(path).Run(); err == nil {
+ if err := exec.Command(path).Run(); err == nil {
t.Fatal("exec on noexec filesystem: got nil, want error")
}
- err = findExecutable(path)
+ _, err = exec.LookPath(path)
if err == nil {
- t.Fatalf("findExecutable: got nil, want error")
+ t.Fatalf("LookPath: got nil, want error")
}
}