diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..70304eb --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,32 @@ +name: Go +on: [push] +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.12 + uses: actions/setup-go@v1 + with: + go-version: 1.12 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Get dependencies + run: go mod download + + - name: Ensure the project is formatted + run: test -z "$(go fmt ./...)" + + - name: Analyse Go code using `vet` + run: go vet ./... + + - name: Ensure the project can be built without issues for tests + run: go run ./generator/cli/thoth/main.go gen --t generate + + - name: Test + run: go run github.com/onsi/ginkgo/ginkgo -r -requireSuite --randomizeAllSpecs --randomizeSuites --failOnPending --cover --trace --race --compilers=2 diff --git a/.gitignore b/.gitignore index f1c181e..a9625a6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,14 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +*.coverprofile +.cover/ +coverage.txt +test-results/ + +# Dependencies +vendor/ + +# IDE +.vscode/ +.idea/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6038a77 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +COVERDIR=$(CURDIR)/.cover +COVERAGEFILE=$(COVERDIR)/cover.out +COVERAGEREPORT=$(COVERDIR)/report.html + +.PHONY: test test-watch coverage coverage-html coverage-ci vet fmt + +test: + @ginkgo --failFast ./... + +test-watch: + @ginkgo watch -cover -r ./... + +coverage-ci: + @mkdir -p $(COVERDIR) + @ginkgo -r -covermode=count --cover --trace ./ + @echo "mode: count" > "${COVERAGEFILE}" + @find . -type f -name '*.coverprofile' -exec cat {} \; -exec rm -f {} \; | grep -h -v "^mode:" >> ${COVERAGEFILE} + +coverage: coverage-ci + @sed -i -e "s|_$(CURDIR)/|./|g" "${COVERAGEFILE}" + @cp "${COVERAGEFILE}" coverage.txt + +coverage-html: + @go tool cover -html="${COVERAGEFILE}" -o $(COVERAGEREPORT) + @xdg-open $(COVERAGEREPORT) 2> /dev/null > /dev/null + +vet: + @go vet ./... + +fmt: + @go fmt ./... + +generate: + @go generate ./... \ No newline at end of file diff --git a/generator/cmd/thoth.go b/generator/cmd/thoth.go index 7731c25..b2e4b21 100644 --- a/generator/cmd/thoth.go +++ b/generator/cmd/thoth.go @@ -15,9 +15,9 @@ var genCommand = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { if cmd.Flag("t").Value.String() == "generate" { - cmd.Flag("d").Value.Set("tests/parse_dir") + cmd.Flag("d").Value.Set("test/parse_dir") cmd.Flag("n").Value.Set("thothGenForTest") - cmd.Flag("s").Value.Set("./tests/gen") + cmd.Flag("s").Value.Set("./test/gen") } if err := gen(cmd, args); err != nil { diff --git a/generator/templates/struct.go b/generator/templates/struct.go index ebf368f..0c5723d 100644 --- a/generator/templates/struct.go +++ b/generator/templates/struct.go @@ -41,6 +41,8 @@ func RenderStruct(_buffer io.StringWriter, fileName string, pkg *myasthurts.Pack _buffer.WriteString(("\n")) _buffer.WriteString(" ") + _buffer.WriteString(("return nil\n")) + _buffer.WriteString("}") } diff --git a/generator/templates/struct.gohtml b/generator/templates/struct.gohtml index 872b7c3..e6c3ab4 100644 --- a/generator/templates/struct.gohtml +++ b/generator/templates/struct.gohtml @@ -11,8 +11,6 @@ package @pkg.Name @raw("\n\n") @for _, s := range structsThoth { @raw("\n") @raw("// Thoth validate\n") @:func(@strings.ToLower(@s.Name()[0:1]) @raw("*")@s.Name()) Thoth() error {@raw("\n") - - - + @raw("return nil\n") @:} } \ No newline at end of file diff --git a/go.mod b/go.mod index 0e66a25..0df25c8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/lab259/go-thoth go 1.12 require ( - github.com/lab259/go-my-ast-hurts v0.0.0-00010101000000-000000000000 + github.com/lab259/go-my-ast-hurts v0.0.0-20191029192755-70e0dd09e3eb github.com/novln/macchiato v1.0.0 github.com/onsi/ginkgo v1.10.2 github.com/onsi/gomega v1.7.0 @@ -19,5 +19,3 @@ require ( golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect ) - -replace github.com/lab259/go-my-ast-hurts => ../go-my-ast-hurts diff --git a/go.sum b/go.sum index fa59d83..1c626f6 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lab259/errors v2.1.0+incompatible/go.mod h1:MDDGb8dSRNqu9IVhE4C+nF2qFqPPO+n6/Nn1AqyI6rI= +github.com/lab259/go-my-ast-hurts v0.0.0-20191029192755-70e0dd09e3eb h1:O/h1tuc0B1A55PxfLdGd/wqpDBYLRYvI07eRNayyJQw= +github.com/lab259/go-my-ast-hurts v0.0.0-20191029192755-70e0dd09e3eb/go.mod h1:ezp+lyGu0NanL8HChvMz1S+G1ZavPdW9NgcD/mpPkzA= github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= diff --git a/go_thoth_test.go b/go_thoth_test.go index 473ccca..989b7cc 100644 --- a/go_thoth_test.go +++ b/go_thoth_test.go @@ -14,7 +14,7 @@ var _ = Describe("GoThoth", func() { env, err := myasthurts.NewEnvironment() Expect(err).ToNot(HaveOccurred()) - pkg, err := env.Parse("./tests/gen") + pkg, err := env.Parse("./test/gen") Expect(err).ToNot(HaveOccurred()) Expect(pkg.Name).To(Equal("any")) @@ -22,14 +22,13 @@ var _ = Describe("GoThoth", func() { refType, ok := pkg.RefTypeByName("Home") Expect(ok).To(BeTrue()) Expect(refType.Name()).To(Equal("Home")) - }) It("should show func User", func() { env, err := myasthurts.NewEnvironment() Expect(err).ToNot(HaveOccurred()) - pkg, err := env.Parse("./tests/gen") + pkg, err := env.Parse("./test/gen") Expect(err).ToNot(HaveOccurred()) Expect(pkg.Name).To(Equal("any")) @@ -37,7 +36,6 @@ var _ = Describe("GoThoth", func() { refType, ok := pkg.RefTypeByName("User") Expect(ok).To(BeTrue()) Expect(refType.Name()).To(Equal("User")) - }) }) }) diff --git a/main b/main deleted file mode 100755 index d8540ed..0000000 Binary files a/main and /dev/null differ diff --git a/test/doc.go b/test/doc.go new file mode 100644 index 0000000..51562d2 --- /dev/null +++ b/test/doc.go @@ -0,0 +1,2 @@ +// Package test contains cross-functional test suites +package test diff --git a/test/gen/.gitignore b/test/gen/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/test/gen/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/parse_dir/model01.parse.go b/test/parse_dir/model01.parse.go similarity index 100% rename from tests/parse_dir/model01.parse.go rename to test/parse_dir/model01.parse.go diff --git a/tests/parse_dir/model02.parse.go b/test/parse_dir/model02.parse.go similarity index 100% rename from tests/parse_dir/model02.parse.go rename to test/parse_dir/model02.parse.go diff --git a/tests/gen/thothGenForTest.go b/test/parse_dir/thothGen.go similarity index 82% rename from tests/gen/thothGenForTest.go rename to test/parse_dir/thothGen.go index 5cf75b2..6fbfcbd 100755 --- a/tests/gen/thothGenForTest.go +++ b/test/parse_dir/thothGen.go @@ -1,4 +1,4 @@ -//go:generate gofmt -s -w thothGenForTest.go +//go:generate gofmt -s -w thothGen.go package any // Thoth validate diff --git a/tests/parse_dir/thothGen.go b/tests/parse_dir/thothGen.go deleted file mode 100755 index 91c9f91..0000000 --- a/tests/parse_dir/thothGen.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:generate gofmt -s -w thothGen.go -package any - - -// Thoth validate -func(h *Home) Thoth() error { - } -// Thoth validate -func(c *Client) Thoth() error { - } -// Thoth validate -func(u *User) Thoth() error { - } \ No newline at end of file