-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into document-symbol
- Loading branch information
Showing
116 changed files
with
2,864 additions
and
1,267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.766 | ||
0.2.786 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package run_test | ||
|
||
import ( | ||
"context" | ||
"embed" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/a-h/templ/cmd/templ/generatecmd/run" | ||
) | ||
|
||
//go:embed testprogram/* | ||
var testprogram embed.FS | ||
|
||
func TestGoRun(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping test in short mode.") | ||
} | ||
|
||
// Copy testprogram to a temporary directory. | ||
dir, err := os.MkdirTemp("", "testprogram") | ||
if err != nil { | ||
t.Fatalf("failed to make test dir: %v", err) | ||
} | ||
files, err := testprogram.ReadDir("testprogram") | ||
if err != nil { | ||
t.Fatalf("failed to read embedded dir: %v", err) | ||
} | ||
for _, file := range files { | ||
srcFileName := "testprogram/" + file.Name() | ||
srcData, err := testprogram.ReadFile(srcFileName) | ||
if err != nil { | ||
t.Fatalf("failed to read src file %q: %v", srcFileName, err) | ||
} | ||
tgtFileName := filepath.Join(dir, file.Name()) | ||
tgtFile, err := os.Create(tgtFileName) | ||
if err != nil { | ||
t.Fatalf("failed to create tgt file %q: %v", tgtFileName, err) | ||
} | ||
defer tgtFile.Close() | ||
if _, err := tgtFile.Write(srcData); err != nil { | ||
t.Fatalf("failed to write to tgt file %q: %v", tgtFileName, err) | ||
} | ||
} | ||
// Rename the go.mod.embed file to go.mod. | ||
if err := os.Rename(filepath.Join(dir, "go.mod.embed"), filepath.Join(dir, "go.mod")); err != nil { | ||
t.Fatalf("failed to rename go.mod.embed: %v", err) | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
cmd string | ||
}{ | ||
{ | ||
name: "Well behaved programs get shut down", | ||
cmd: "go run .", | ||
}, | ||
{ | ||
name: "Badly behaved programs get shut down", | ||
cmd: "go run . -badly-behaved", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx := context.Background() | ||
cmd, err := run.Run(ctx, dir, tt.cmd) | ||
if err != nil { | ||
t.Fatalf("failed to run program: %v", err) | ||
} | ||
|
||
time.Sleep(1 * time.Second) | ||
|
||
pid := cmd.Process.Pid | ||
|
||
if err := run.KillAll(); err != nil { | ||
t.Fatalf("failed to kill all: %v", err) | ||
} | ||
|
||
// Check the parent process is no longer running. | ||
if err := cmd.Process.Signal(os.Signal(syscall.Signal(0))); err == nil { | ||
t.Fatalf("process %d is still running", pid) | ||
} | ||
// Check that the child was stopped. | ||
body, err := readResponse("http://localhost:7777") | ||
if err == nil { | ||
t.Fatalf("child process is still running: %s", body) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func readResponse(url string) (body string, err error) { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return body, err | ||
} | ||
defer resp.Body.Close() | ||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return body, err | ||
} | ||
return string(b), nil | ||
} |
Oops, something went wrong.