tests: Handle test cases without a go.mod

This commit is contained in:
adisbladis 2022-05-30 18:33:22 +08:00
parent ce3a6771f0
commit c72445c826

View file

@ -70,13 +70,16 @@ func runTest(rootDir string, testDir string) error {
prefix := testDir prefix := testDir
cmdPath := filepath.Join(rootDir, "..", "gomod2nix") cmdPath := filepath.Join(rootDir, "..", "gomod2nix")
testDir = filepath.Join(rootDir, testDir) testDir = filepath.Join(rootDir, testDir)
err := runProcess(prefix, cmdPath, "--dir", testDir, "--outdir", testDir)
if err != nil { if _, err := os.Stat(filepath.Join(testDir, "go.mod")); err == nil {
return err err := runProcess(prefix, cmdPath, "--dir", testDir, "--outdir", testDir)
if err != nil {
return err
}
} }
buildExpr := fmt.Sprintf("with (import <nixpkgs> { overlays = [ (import %s/../overlay.nix) ]; }); callPackage %s {}", rootDir, testDir) buildExpr := fmt.Sprintf("with (import <nixpkgs> { overlays = [ (import %s/../overlay.nix) ]; }); callPackage %s {}", rootDir, testDir)
err = runProcess(prefix, "nix-build", "--no-out-link", "--expr", buildExpr) err := runProcess(prefix, "nix-build", "--no-out-link", "--expr", buildExpr)
if err != nil { if err != nil {
return err return err
} }