Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/gg: initial commit of -infiles: flag prefix support
- Loading branch information
Showing
8 changed files
with
274 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Test for special -infiles: flag | ||
|
||
# first run | ||
gg -p 1 -trace ./... | ||
cmpenv stderr trace1 | ||
cmp p1/gen_input_txt_p2.go p1/input.txt | ||
cmp p1/gen_another_txt_p2.go p2/another.txt | ||
|
||
cp p1/input.txt.2 p1/input.txt | ||
|
||
# second run | ||
gg -p 1 -trace ./... | ||
cmpenv stderr trace2 | ||
cmp p1/gen_input_txt_p2.go p1/input.txt.2 | ||
cmp p1/gen_another_txt_p2.go p2/another.txt | ||
|
||
cp p2/another.txt.2 p2/another.txt | ||
|
||
# third run | ||
gg -p 1 -trace ./... | ||
cmpenv stderr trace3 | ||
cmp p1/gen_input_txt_p2.go p1/input.txt.2 | ||
cmp p1/gen_another_txt_p2.go p2/another.txt.2 | ||
|
||
-- go.mod -- | ||
module mod.com | ||
|
||
-- p1/p1.go -- | ||
package p1 | ||
|
||
//go:generate gobin -m -run mod.com/p2 -infiles:test input.txt | ||
//go:generate gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
|
||
-- p1/input.txt -- | ||
package p1 | ||
|
||
// this is input.txt | ||
|
||
-- p1/input.txt.2 -- | ||
package p1 | ||
|
||
// this is input.txt.2 | ||
|
||
-- p2/p2.go -- | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
"os" | ||
"strings" | ||
"path/filepath" | ||
) | ||
|
||
var ( | ||
fTest = flag.String("infiles:test", "", "our test file") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
infile, err := os.Open(*fTest) | ||
if err != nil { | ||
panic(err) | ||
} | ||
outfile, err := os.Create("gen_" + strings.Replace(filepath.Base(*fTest), ".", "_", -1) + "_p2.go") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if _, err := io.Copy(outfile, infile); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
-- p2/another.txt -- | ||
package p1 | ||
|
||
// another.txt in p2 | ||
-- p2/another.txt.2 -- | ||
package p1 | ||
|
||
// another.txt.2 in p2 | ||
-- trace1 -- | ||
go list -deps -test -json ./... | ||
hash {Pkg: mod.com/p2 [G]} | ||
hash gobinModDep gobinModDep: mod.com/p2 (mod.com/p2) | ||
generate {Pkg: mod.com/p1 [G]} | ||
run generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
run generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
generate {Pkg: mod.com/p1 [G]} | ||
run generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
run generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
hash {Pkg: mod.com/p1 [G]} | ||
-- trace2 -- | ||
go list -deps -test -json ./... | ||
hash {Pkg: mod.com/p2 [G]} | ||
hash gobinModDep gobinModDep: mod.com/p2 (mod.com/p2) | ||
generate {Pkg: mod.com/p1 [G]} | ||
run generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
run generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
generate {Pkg: mod.com/p1 [G]} | ||
run generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
run generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
hash {Pkg: mod.com/p1 [G]} | ||
-- trace3 -- | ||
go list -deps -test -json ./... | ||
hash {Pkg: mod.com/p2 [G]} | ||
hash gobinModDep gobinModDep: mod.com/p2 (mod.com/p2) | ||
generate {Pkg: mod.com/p1 [G]} | ||
run generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
run generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
generate {Pkg: mod.com/p1 [G]} | ||
run generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test input.txt | ||
run generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
ran generator: gobin -m -run mod.com/p2 -infiles:test ../p2/another.txt | ||
hash {Pkg: mod.com/p1 [G]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters