1 // Copyright (c) 2019, Daniel Martà <mvdan@mvdan.cc>
2 // See LICENSE for licensing information
16 "github.com/rogpeppe/go-internal/testscript"
19 func TestMain(m *testing.M) {
20 os.Exit(testscript.RunMain(m, map[string]func() int{
25 func TestScripts(t *testing.T) {
27 testscript.Run(t, testscript.Params{
28 Dir: filepath.Join("testdata", "scripts"),
29 Setup: func(env *testscript.Env) error {
30 mux := http.NewServeMux()
31 mux.HandleFunc("/plain", func(w http.ResponseWriter, r *http.Request) {
32 fmt.Fprintf(w, "plaintext")
34 mux.HandleFunc("/redir-1", func(w http.ResponseWriter, r *http.Request) {
35 http.Redirect(w, r, "/plain", http.StatusMovedPermanently)
37 mux.HandleFunc("/redir-2", func(w http.ResponseWriter, r *http.Request) {
38 http.Redirect(w, r, "/redir-1", http.StatusMovedPermanently)
40 ln, err := net.Listen("tcp", ":0")
44 server := &http.Server{Handler: mux}
46 env.Vars = append(env.Vars, "SERVER=http://"+ln.Addr().String())
48 if err := server.Shutdown(context.TODO()); err != nil {
54 Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
55 "expand": func(ts *testscript.TestScript, neg bool, args []string) {
57 ts.Fatalf("unsupported: ! expand")
60 ts.Fatalf("usage: expand file...")
62 for _, arg := range args {
63 data := ts.ReadFile(arg)
64 data = os.Expand(data, ts.Getenv)
65 err := ioutil.WriteFile(ts.MkAbs(arg), []byte(data), 0666)