-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/rhysd/vim-startuptime | ||
|
||
go 1.16 | ||
|
||
require github.com/google/go-cmp v0.6.0 // indirect |
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,2 @@ | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= |
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,64 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestParseOptionsOK(t *testing.T) { | ||
var b bytes.Buffer | ||
|
||
o, s := parseOptions(&b, []string{"vim-startuptime", "-count", "3", "-vimpath", "nvim", "-script", "-warmup", "5", "-verbose", "--", "--foo"}) | ||
if s >= 0 { | ||
t.Fatal("unexpected exit with status:", s) | ||
} | ||
|
||
want := &options{ | ||
count: 3, | ||
vimPath: "nvim", | ||
script: true, | ||
extraArgs: []string{"--foo"}, | ||
warmup: 5, | ||
verbose: true, | ||
} | ||
|
||
if !cmp.Equal(o, want, cmp.AllowUnexported(options{})) { | ||
t.Fatal(cmp.Diff(o, want, cmp.AllowUnexported(options{}))) | ||
} | ||
|
||
stderr := b.String() | ||
if stderr != "" { | ||
t.Fatalf("Unexpected stderr output %q", stderr) | ||
} | ||
} | ||
|
||
func TestParseOptionsUnknownFlag(t *testing.T) { | ||
var b bytes.Buffer | ||
|
||
_, s := parseOptions(&b, []string{"vim-startuptime", "-foo"}) | ||
if s <= 0 { | ||
t.Fatal("unexpected status:", s) | ||
} | ||
|
||
stderr := b.String() | ||
if !strings.Contains(stderr, "flag provided but not defined: -foo") { | ||
t.Fatal("unexpected error output to stderr:", stderr) | ||
} | ||
} | ||
|
||
func TestParseOptionsHelpOutput(t *testing.T) { | ||
var b bytes.Buffer | ||
|
||
_, s := parseOptions(&b, []string{"vim-startuptime", "-help"}) | ||
if s != 0 { | ||
t.Fatal("unexpected status:", s) | ||
} | ||
|
||
stderr := b.String() | ||
if !strings.HasPrefix(stderr, "Usage: vim-startuptime [flags] [-- VIMARGS...]") { | ||
t.Fatal("unexpected help output to stderr:", stderr) | ||
} | ||
} |