Skip to content

Commit

Permalink
Fix subpath builds / pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus committed May 12, 2022
1 parent b6598d5 commit b32f665
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
8 changes: 4 additions & 4 deletions modutils/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ var (
// Get is an alias to DefaultExecutor.Get.
Get = DefaultExecutor.Get

// GetDirE is an alias to DefaultExecutor.GetDirE.
GetDirE = DefaultExecutor.DirE
// GetDir is an alias to DefaultExecutor.GetDir.
GetDir = DefaultExecutor.Dir
// DirE is an alias to DefaultExecutor.DirE.
DirE = DefaultExecutor.DirE
// Dir is an alias to DefaultExecutor.Dir.
Dir = DefaultExecutor.Dir

// BuildE is an alias to DefaultExecutor.BuildE.
BuildE = DefaultExecutor.BuildE
Expand Down
2 changes: 1 addition & 1 deletion modutils/modutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (e *Executor) BuildE(filename, name string, parts ...string) error {

target := "."
if len(parts) > 0 {
target += path.Join(parts...)
target = "./" + path.Join(parts...)
}

if err := e.build(name, dir, target, filename); err != nil {
Expand Down
17 changes: 17 additions & 0 deletions modutils/modutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ var _ = Describe("Modutils", func() {
Expect(filepath.Join(dir, "go.mod")).To(BeARegularFile())
Expect(filepath.Join(dir, "main.go")).To(BeARegularFile())
})

It("should get the directory of the specified module", func() {
dir, err := executor.DirE("example.org/testmod2", "submain")
Expect(err).NotTo(HaveOccurred())
Expect(dir).To(BeADirectory())
Expect(filepath.Join(dir, "main.go")).To(BeARegularFile())
})
})

Describe("BuildE", func() {
Expand All @@ -74,6 +81,16 @@ var _ = Describe("Modutils", func() {

Expect(session.Wait(1 * time.Second).Out).To(gbytes.Say("Hello, World!"))
})

It("should build the module via another module and subpath", func() {
dstFilename := filepath.Join(GinkgoT().TempDir(), "hello-world")
Expect(executor.BuildE(dstFilename, "example.org/testmod2", "submain")).To(Succeed())

session, err := gexec.Start(exec.Command(dstFilename), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Expect(session.Wait(1 * time.Second).Out).To(gbytes.Say("Hello, Submain!"))
})
})
})
})
7 changes: 7 additions & 0 deletions testdata/testmod2/submain/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello, Submain!")
}

0 comments on commit b32f665

Please sign in to comment.