forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new test has been added in order to verify that all code under _examples is up to date and has not broken due to API changes. This test runs as the last step of the test.yml CI workflow. Closes go-git#912.
- Loading branch information
1 parent
0dfff25
commit f013380
Showing
2 changed files
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package git | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestBuildExamples(t *testing.T) { | ||
examplesDir := os.Getenv("EXAMPLES_DIR") | ||
if len(examplesDir) == 0 { | ||
t.Skip("EXAMPLES_DIR not set") | ||
} | ||
|
||
examplesDir, err := filepath.Abs(examplesDir) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
glob := filepath.Join(examplesDir, "/**/main.go") | ||
matches, err := filepath.Glob(glob) | ||
for _, match := range matches { | ||
testName, err := filepath.Rel(examplesDir, match) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
testName = filepath.Dir(testName) | ||
t.Run(testName, func(t *testing.T) { | ||
cmd := exec.Command("go", "build", "-o", os.DevNull) | ||
cmd.Dir = filepath.Dir(match) | ||
if err := cmd.Run(); err != nil { | ||
t.Error(err.Error()) | ||
} | ||
}) | ||
} | ||
} |