Skip to content

Commit

Permalink
ref: move generators pkg inside src (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 25, 2024
1 parent 660ce55 commit 3c4043e
Show file tree
Hide file tree
Showing 41 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# vendor/

dist/
generators/gola/out/
src/generators/gola/out/

# go-task intermediate files like checksums
#
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"

"github.com/samber/lo"
"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/src/generators/gola"
nef "github.com/snivilised/nefilim"
)

Expand All @@ -24,7 +24,7 @@ var (
writeFlag = flag.Bool("write", false, "write generated code?")
signFlag = flag.Bool("sign", false, "show signature of existing code only")

testPath = filepath.Join("generators", "gola", "out", "assistant")
testPath = filepath.Join("src", "generators", "gola", "out", "assistant")
sourcePath = filepath.Join("src", "assistant")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gola
import (
"bytes"

"github.com/snivilised/cobrass/generators/gola/internal/collections"
"github.com/snivilised/cobrass/src/generators/gola/internal/collections"
)

type executionInfo struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/src/generators/gola"
nef "github.com/snivilised/nefilim"

. "github.com/onsi/gomega/types" //nolint:revive // gomega ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("HyperGen", Ordered, func() {

BeforeAll(func() {
repo = Repo("../..")
testPath = filepath.Join("generators", "gola", "out", "assistant")
testPath = filepath.Join("src", "generators", "gola", "out", "assistant")
sourcePath = filepath.Join("src", "assistant")
_ = testPath
_ = sourcePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing/fstest"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/lab"
nef "github.com/snivilised/nefilim"
)

Expand Down Expand Up @@ -43,7 +44,7 @@ func (f *TestMemFS) Create(name string) (*os.File, error) {
}

file := &fstest.MapFile{
Mode: Perms.File,
Mode: lab.Perms.File,
}

f.MapFS[name] = file
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,28 @@ package gola_test
import (
_ "embed"
"fmt"
"io/fs"
"os"
"path/filepath"

. "github.com/onsi/ginkgo/v2" //nolint:revive // ok
. "github.com/onsi/gomega" //nolint:revive // ok
"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/src/generators/gola"
"github.com/snivilised/cobrass/src/internal/lab"
nef "github.com/snivilised/nefilim"
)

var (
Perms = struct {
File fs.FileMode
Dir fs.FileMode
}{
File: 0o666,
Dir: 0o777,
}
)

type setupFile struct {
path string
data []byte
}

func setup(fS nef.UniversalFS, directoryPath string, files ...setupFile) {
if e := fS.MakeDirAll(directoryPath, Perms.Dir); e != nil {
if e := fS.MakeDirAll(directoryPath, lab.Perms.Dir); e != nil {
Fail(fmt.Sprintf("%q, path: %q", e.Error(), directoryPath))
}

for _, f := range files {
if e := fS.WriteFile(f.path, f.data, Perms.File); e != nil {
if e := fS.WriteFile(f.path, f.data, lab.Perms.File); e != nil {
Fail(fmt.Sprintf("%q, path: %q", e.Error(), f.path))
}
}
Expand All @@ -59,8 +49,8 @@ var _ = Describe("Signature", Ordered, func() {

BeforeAll(func() {
repo = Repo("../..")
testPath = filepath.Join("generators", "gola", "out", "assistant")
sourcePath = filepath.Join("src", "assistant")
testPath = filepath.Join("src", "generators", "gola", "out", "assistant")
sourcePath = filepath.Join("assistant")

Check failure on line 53 in src/generators/gola/signature_test.go

View workflow job for this annotation

GitHub Actions / lint

badCall: suspicious Join on 1 argument (gocritic)
})

Context("sign", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"text/template"

"github.com/samber/lo"
"github.com/snivilised/cobrass/generators/gola/internal/collections"
"github.com/snivilised/cobrass/src/generators/gola/internal/collections"
nef "github.com/snivilised/nefilim"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok

"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/src/generators/gola"
nef "github.com/snivilised/nefilim"
)

Expand All @@ -30,7 +30,7 @@ var _ = Describe("SourceCodeData", Ordered, func() {

BeforeAll(func() {
repo = Repo("../..")
testPath = filepath.Join("generators", "gola", "out", "assistant")
testPath = filepath.Join("src", "generators", "gola", "out", "assistant")
sourcePath = filepath.Join("src", "assistant")
fS = nef.NewUniversalABS()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ package gola
import (
_ "embed"
"fmt"
"io/fs"
"path"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/lab"
nef "github.com/snivilised/nefilim"
)

var (
noData = struct{}{}
//go:embed signature.GO-HASH.txt
RegisteredHash string

Perms = struct {
File fs.FileMode
Dir fs.FileMode
}{
File: 0o666, //nolint:mnd // ok (pedantic)
Dir: 0o777, //nolint:mnd // ok (pedantic)
}
)

type SourceCodeGenerator struct {
Expand Down Expand Up @@ -166,15 +158,15 @@ func (g *SourceCodeGenerator) flush(outputPath string, yield *generatedYield) er

if err := g.fS.MakeDirAll(
directory,
Perms.Dir,
lab.Perms.Dir,
); err != nil {
return fmt.Errorf("failed to ensure parent directory '%v' exists (%v)", directory, err)
}

if err := g.fS.WriteFile(
outputPath,
yield.buffer.Bytes(),
Perms.File,
lab.Perms.File,
); err != nil {
return fmt.Errorf("failed to write generated code to '%v' (%v)", outputPath, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok

"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/src/generators/gola"
nef "github.com/snivilised/nefilim"
)

Expand All @@ -18,7 +18,7 @@ var _ = Describe("SourceCodeGenerator", Ordered, func() {

BeforeAll(func() {
repo = Repo("../..")
testPath = filepath.Join("generators", "gola", "out", "assistant")
testPath = filepath.Join("src", "generators", "gola", "out", "assistant")
fS = NewTestMemFS()
})

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions src/internal/lab/test-utilities.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package lab

import (
"io/fs"
"path/filepath"
"runtime"
"strings"
)

var (
Perms = struct {
File fs.FileMode
Dir fs.FileMode
}{
File: 0o666, //nolint:mnd // ok (pedantic)
Dir: 0o777, //nolint:mnd // ok (pedantic)
}
)

func Path(parent, relative string) string {
segments := strings.Split(relative, "/")
return filepath.Join(append([]string{parent}, segments...)...)
Expand Down

0 comments on commit 3c4043e

Please sign in to comment.