Skip to content

Commit

Permalink
use command like usage instead of genertate like usage in command level
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
crhntr committed Aug 19, 2024
1 parent 28825aa commit 69b1935
Show file tree
Hide file tree
Showing 19 changed files with 1 addition and 111 deletions.
1 change: 1 addition & 0 deletions cmd/muxt/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func generateCommand(args []string, workingDirectory string, getEnv func(string)
g.Package = list[i]
} else if len(list) > 0 {
g.Package = list[0]
g.goPackage = list[0].ID
}
ts, err := source.Templates(workingDirectory, g.templatesVariable, g.Package.Fset, g.Package.Syntax, g.Package.EmbedFiles)
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/argument_context.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -25,7 +21,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/argument_path_param.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -25,7 +21,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/argument_request.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -25,7 +21,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/argument_response.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -25,7 +21,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/error_duplicate_pattern.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

! muxt generate --routes-func=TemplateRoutes
stderr 'duplicate route pattern: GET /'

Expand Down Expand Up @@ -30,5 +26,4 @@ import (
//go:embed template.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/error_unknown_flag.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

! muxt generate --routes-func=TemplateRoutes --unknown
stderr 'flag'

Expand All @@ -22,5 +18,4 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.New()
26 changes: 0 additions & 26 deletions cmd/muxt/testdata/generate/error_wrong_gopacakge.txtar

This file was deleted.

5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/override_execute.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=13
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes
! stdout execute

Expand Down Expand Up @@ -31,7 +27,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))

func execute(res http.ResponseWriter, _ *http.Request, t *template.Template, code int, data any) {
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/path_end.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -27,7 +23,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/path_param.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -27,7 +23,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/simple_get.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -27,7 +23,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/simple_handler.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -25,7 +21,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/simple_patch.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes

exec go test -cover
Expand All @@ -27,7 +23,6 @@ import (
//go:embed *.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
-- template_test.go --
package server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=12
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes
stdout 'Routes has route for GET /'

Expand All @@ -27,6 +23,5 @@ var (
//go:embed *.gohtml
formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
templates = template.Must(template.ParseFS(formHTML, "*"))
)
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/templates_glob_filter.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes
! stdout 'Routes has route for GET /example'

Expand Down Expand Up @@ -46,7 +42,6 @@ import (
//go:embed assets
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "assets/*.gohtml"))
-- template_test.go --
package server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=12
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes
stdout 'Routes has route for GET /'
stdout 'Routes has route for GET /form'
Expand Down Expand Up @@ -38,5 +34,4 @@ import (
//go:embed form.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/templates_multiple_globs.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=11
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes
stdout 'Routes has route for GET /'
stdout 'Routes has route for GET /form'
Expand Down Expand Up @@ -37,5 +33,4 @@ import (
//go:embed index.gohtml form.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.ParseFS(formHTML, "*"))
5 changes: 0 additions & 5 deletions cmd/muxt/testdata/generate/templates_multiple_parsefs.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env GOLINE=14
env GOPACKAGE=server
env GOFILE=template.go

muxt generate --routes-func=TemplateRoutes
stdout 'Routes has route for GET /'
stdout 'Routes has route for GET /form'
Expand Down Expand Up @@ -40,5 +36,4 @@ var indexHTML embed.FS
//go:embed form.gohtml
var formHTML embed.FS

//go:generate go run github.com/crhntr/muxt/cmd/muxt
var templates = template.Must(template.Must(template.ParseFS(formHTML, "*")).ParseFS(indexHTML, "*"))

0 comments on commit 69b1935

Please sign in to comment.