diff --git a/internal/check_update.go b/internal/check_update.go index 26c34d9..656bf0c 100644 --- a/internal/check_update.go +++ b/internal/check_update.go @@ -74,7 +74,7 @@ type releaseInfo struct { } func (ri releaseInfo) display() { - fmt.Printf("\nnote: new `%s` of iris is now available at `%s` \n\nfull release article: \n%s \n%s\n", ri.TagName, ri.HTMLURL, ri.Name, ri.Body) + fmt.Printf("\nnote: new `%s` of bench is now available at `%s` \n\nfull release article: \n%s \n%s\n", ri.TagName, ri.HTMLURL, ri.Name, ri.Body) } func CheckForUpdates(currentVersion string) { @@ -84,7 +84,7 @@ func CheckForUpdates(currentVersion string) { return } - url := "https://api.github.com/repos/Shravan-1908/iris/releases/latest" + url := "https://api.github.com/repos/Shravan-1908/bench/releases/latest" releaseInfo := releaseInfo{} resp, err := http.Get(url) if err != nil { @@ -96,6 +96,7 @@ func CheckForUpdates(currentVersion string) { } json.Unmarshal(data, &releaseInfo) writeLastCheckedTime(now) + if compareSemverStrings(releaseInfo.TagName, currentVersion) != greater { // no new version return diff --git a/internal/export.go b/internal/export.go index e3003e9..c188d9e 100644 --- a/internal/export.go +++ b/internal/export.go @@ -170,7 +170,17 @@ func (result *Result) Export(exportFormats string) { Log("red", "Failed to export the results to json.") return } - writeToFile(string(jsonText), "bench-summary.json") + e = writeToFile(string(jsonText), "bench-summary.json") + if e == nil { + absPath, err := filepath.Abs("bench-summary.json") + if err != nil { + Log("red", "unable to get the absolute path for json file: "+err.Error()) + } else { + Log("green", "Successfully wrote benchmark summary to `"+absPath+"`.") + } + } else { + Log("red", "Unable to write to file ./bench-summary.json: "+e.Error()) + } } else if exportFormat == "csv" { csvify(result) diff --git a/internal/utils.go b/internal/utils.go index bde17a4..08b82b8 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -62,21 +62,13 @@ func getBenchDir() string { panic(e) } - // * determining iris's directory - dir := filepath.Join(usr.HomeDir, ".iris") + // * determining bench's directory + dir := filepath.Join(usr.HomeDir, ".bench") if !checkPathExists(dir) { os.Mkdir(dir, os.ModePerm) } - subDirs := []string{"wallpapers", "temp", "cache"} - for _, subDir := range subDirs { - dirPath := filepath.Join(dir, subDir) - if !checkPathExists(dirPath) { - os.Mkdir(dirPath, os.ModePerm) - } - } - return dir } diff --git a/internal/utils_test.go b/internal/utils_test.go index f60a9f3..c811d5e 100644 --- a/internal/utils_test.go +++ b/internal/utils_test.go @@ -1,8 +1,8 @@ package internal import ( - "testing" "os" + "testing" ) func Test_format(t *testing.T) { @@ -17,20 +17,20 @@ func Test_format(t *testing.T) { want string }{ { - name: "empty test", - args: args{"", map[string]string{}}, + name: "empty test", + args: args{"", map[string]string{}}, want: "", }, { - name: "name test", - args: args{"hello this is me, ${name}", map[string]string{"name": "Shravan"}}, + name: "name test", + args: args{"hello this is me, ${name}", map[string]string{"name": "Shravan"}}, want: "hello this is me, Shravan", }, { - name: "long sentence test", - args: args{"${go} offers cool concurrency features like ${c1} and ${c2}. and it's ${adj}!", map[string]string{"go": "Golang", "c1": "goroutines", "c2": "channels", "adj": "amazing"}}, + name: "long sentence test", + args: args{"${go} offers cool concurrency features like ${c1} and ${c2}. and it's ${adj}!", map[string]string{"go": "Golang", "c1": "goroutines", "c2": "channels", "adj": "amazing"}}, want: "Golang offers cool concurrency features like goroutines and channels. and it's amazing!", }, } @@ -71,7 +71,7 @@ func Test_writeToFile(t *testing.T) { wantErr: true, }, } - + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if err := writeToFile(tt.args.text, tt.args.filename); (err != nil) != tt.wantErr { diff --git a/main.go b/main.go index e589635..ea65abf 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ const ( // NAME is the executable name. NAME = "bench" // VERSION is the executable version. - VERSION = "v0.4.0" + VERSION = "v0.2.0" ) // NO_COLOR is a global variable that is used to determine whether or not to enable color output. @@ -91,7 +91,7 @@ func main() { command, err := shlex.Split(args["command"].Value) if err != nil { - internal.Log("red", "unable to parse the given command: " + args["command"].Value) + internal.Log("red", "unable to parse the given command: "+args["command"].Value) internal.Log("white", err.Error()) return } @@ -128,7 +128,7 @@ func main() { // warmup runs for i := 0; i < warmupRuns; i++ { // todo replace running logs with a progress bar in non-verbose mode - internal.Log("purple", fmt.Sprintf("***********\nRunning warmup %d\n***********", i + 1)) + internal.Log("purple", fmt.Sprintf("***********\nRunning warmup %d\n***********", i+1)) _, e := run(command, verbose, ignoreError) if e != nil { return @@ -164,11 +164,11 @@ func main() { panic("unable to parse duration from string: " + stddevString + "\n" + err.Error()) } result := internal.Result{ - Started: started, - Ended: ended, - Command: strings.Join(command, " "), - Iterations: iterations, - Average: avgDuration.String(), + Started: started, + Ended: ended, + Command: strings.Join(command, " "), + Iterations: iterations, + Average: avgDuration.String(), StandardDeviation: stddevDuration.String(), }