|
5 | 5 | "log" |
6 | 6 | "os" |
7 | 7 | "os/exec" |
| 8 | + "runtime" |
8 | 9 | "testing" |
9 | 10 |
|
10 | 11 | "github.com/dunglas/frankenphp" |
@@ -45,6 +46,27 @@ func TestExecuteCLICode(t *testing.T) { |
45 | 46 | assert.Equal(t, stdoutStderrStr, `Hello World`) |
46 | 47 | } |
47 | 48 |
|
| 49 | +// Regression test for https://github.com/php/frankenphp/issues/1902. A |
| 50 | +// long-running CLI script that installs pcntl_signal handlers must |
| 51 | +// receive its own signals reliably |
| 52 | +func TestExecuteScriptCLISignals(t *testing.T) { |
| 53 | + if runtime.GOOS == "windows" { |
| 54 | + t.Skip("pcntl is not available on Windows") |
| 55 | + } |
| 56 | + if _, err := os.Stat("internal/testcli/testcli"); err != nil { |
| 57 | + t.Skip("internal/testcli/testcli has not been compiled, run `cd internal/testcli/ && go build`") |
| 58 | + } |
| 59 | + |
| 60 | + cmd := exec.Command("internal/testcli/testcli", "testdata/command-pcntl.php") |
| 61 | + stdoutStderr, err := cmd.CombinedOutput() |
| 62 | + var exitError *exec.ExitError |
| 63 | + if errors.As(err, &exitError) && exitError.ExitCode() == 2 { |
| 64 | + t.Skipf("pcntl/posix not available: %s", stdoutStderr) |
| 65 | + } |
| 66 | + assert.NoError(t, err, "output: %s", stdoutStderr) |
| 67 | + assert.Contains(t, string(stdoutStderr), "ok") |
| 68 | +} |
| 69 | + |
48 | 70 | func ExampleExecuteScriptCLI() { |
49 | 71 | if len(os.Args) <= 1 { |
50 | 72 | log.Println("Usage: my-program script.php") |
|
0 commit comments