Skip to content

Commit cc4e166

Browse files
authored
Merge pull request #22 from moznion/tweak_for_#21
Tweak for #21
2 parents 79cc85e + 14ae153 commit cc4e166

File tree

10 files changed

+42
-229
lines changed

10 files changed

+42
-229
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/Godeps/
1313

1414
/internal/test/*_gen.go
15+
/internal/test/**/*_gen.go
1516
/dist/
1617

1718
/gonstructor

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ build4test: clean
1515
gen4test: build4test
1616
go generate $(PKGS)
1717

18-
test: gen4test
18+
test: clean-test-gen gen4test
1919
go test -v $(PKGS)
2020

21+
clean-test-gen:
22+
rm -f internal/test/*_gen.go internal/test/**/*_gen.go
23+
2124
lint:
2225
lint:
2326
golangci-lint run ./...

cmd/gonstructor/gonstructor.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ func main() {
7979
log.Fatal(fmt.Errorf("[error] failed to parse a file: %w", err))
8080
}
8181

82-
var (
83-
alreadyOpenedWithTruncFilesSet = map[string]bool{}
84-
fileHeaderGenerated = false
85-
rootStmt = g.NewRoot()
86-
)
82+
alreadyOpenedWithTruncFilesSet := map[string]bool{}
83+
fileHeaderGenerated := false
84+
rootStmt := g.NewRoot()
8785
for i, typeName := range typeNames {
8886
fields, err := constructor.CollectConstructorFieldsFromAST(typeName, astFiles)
8987
if err != nil {
@@ -140,7 +138,8 @@ func main() {
140138
if *withGetter {
141139
rootStmt = rootStmt.AddStatements(internal.GenerateGetters(typeName, fields))
142140
}
143-
if i != len(typeNames)-1 {
141+
142+
if i != len(typeNames)-1 { // insert a newline *between* the generated type-code (i.e. don't append a trailing newline)
144143
rootStmt = rootStmt.AddStatements(g.NewNewline())
145144
}
146145
}

internal/test/init_return_propagation/structure_with_init_bar_gen.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

internal/test/init_return_propagation/structure_with_init_buz_gen.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

internal/test/init_return_propagation/structure_with_init_foo_gen.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

internal/test/init_return_propagation/structure_with_init_qux_gen.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

internal/test/multitypes/alpha_and_bravo_gen.go

Lines changed: 0 additions & 86 deletions
This file was deleted.

internal/test/multitypes/structure_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@ func TestStructureBuilder(t *testing.T) {
5656
assert.EqualValues(t, givenBuzString, gotBravo.buz)
5757
assert.EqualValues(t, givenQuxInt, gotBravo.qux)
5858
}
59+
60+
func TestStructureWhichNeedsImport1Instantiation(t *testing.T) {
61+
s := NewStructureWhichNeedsImport1(nil)
62+
assert.IsType(t, &StructureWhichNeedsImport1{}, s)
63+
}
64+
65+
func TestStructureWhichNeedsImport2Instantiation(t *testing.T) {
66+
s := NewStructureWhichNeedsImport2(nil)
67+
assert.IsType(t, &StructureWhichNeedsImport2{}, s)
68+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package multitypes
2+
3+
import (
4+
"io"
5+
"net"
6+
)
7+
8+
// NOTE:
9+
// This structure file is for checking whether the compilation passes for the generated file according to this.
10+
// ref: https://github.com/moznion/gonstructor/pull/21
11+
//
12+
// Until the above pull request, the generated code hadn't passed the compilation.
13+
14+
//go:generate sh -c "$(cd ./\"$(git rev-parse --show-cdup)\" || exit; pwd)/dist/gonstructor_test --type=StructureWhichNeedsImport1 --type=StructureWhichNeedsImport2 --output structure_with_multiple_imports_gen.go --constructorTypes=allArgs,builder --withGetter"
15+
16+
type StructureWhichNeedsImport1 struct {
17+
foo net.Conn
18+
}
19+
20+
type StructureWhichNeedsImport2 struct {
21+
bar io.Reader
22+
}

0 commit comments

Comments
 (0)