@@ -65,25 +65,29 @@ func ExampleGetLatestVer() {
65
65
}
66
66
67
67
func ExampleGetPackageInformation () {
68
- pkgInfo := goutil .GetPackageInformation ([]string {"../../cmd/testdata/check_success/gal" })
68
+ // Prepare the path of go binary module for the example
69
+ nameDirCheckSuccess := "check_success"
70
+ nameFileBin := "gal"
71
+
72
+ if runtime .GOOS == "windows" {
73
+ nameDirCheckSuccess = "check_success_for_windows"
74
+ nameFileBin = "gal.exe" // remember the extension
75
+ }
76
+
77
+ pathFileBin := filepath .Join (".." , ".." , "cmd" , "testdata" , nameDirCheckSuccess , nameFileBin )
78
+
79
+ pkgInfo := goutil .GetPackageInformation ([]string {pathFileBin })
69
80
if pkgInfo == nil {
70
81
log .Fatal ("example GetPackageInformation failed. The returned package information is nil" )
71
82
}
72
83
73
84
// Expected package information on Linux and macOS
74
85
want := []string {
75
- "gal" ,
86
+ nameFileBin ,
76
87
"github.com/nao1215/gal/cmd/gal" ,
77
88
"github.com/nao1215/gal" ,
78
89
}
79
90
80
- // On Windows, paths are missing
81
- if runtime .GOOS == "windows" {
82
- want = []string {
83
- "gal" , "" , "" ,
84
- }
85
- }
86
-
87
91
// Actual package information
88
92
got := []string {
89
93
pkgInfo [0 ].Name ,
@@ -99,8 +103,9 @@ func ExampleGetPackageInformation() {
99
103
// Output: Example GetPackageInformation: OK
100
104
}
101
105
102
- func ExampleGetPackageVersion () {
106
+ func ExampleGetPackageVersion_unknown () {
103
107
// GetPackageVersion returns the version of the package installed via `go install`.
108
+ // In this example, we specify a package that is not installed.
104
109
got := goutil .GetPackageVersion ("gup_dummy" )
105
110
106
111
// Non existing binary returns "unknown"
0 commit comments