Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the tests to run on Windows #2615

Merged
merged 4 commits into from
Sep 24, 2021
Merged

Conversation

vovcacik
Copy link
Contributor

I needed to write some tests, but the existing tests were failing on Windows. In this pull request you can find changes that make the tests run and pass on both platforms.

The first commit prepares the ground and make some strings in the tests parametric. I'm using the text/templates package from Go. The second commit then contains all changes related to Windows platform.

Most of the "expected" strings in terminal.go test were changed to
"text/template" values. Quotes in those string were parametrized in
the templates. Two functions handling templates were added
for convenience.

Templates has the advantage of:
- parametrize repetitive strings inside "expected" values
  - inner and outer quotes were parametrized in templates
  - long and confusing test values are more readable
- templates can be localized for other operating systems

+func checkFormat(string) in terminal_test.go
+func TemplateToString(string, interface{}) string in util/templates.go
Testing on unix is unchanged.
Testing on windows was achieved by:
- some test strings are OS dependent
  - e.g. "echo abc && ..." in windows the parser is greedy and the first
    argument will be "abc " (note the whitespace)
- quotes in some test strings were localized for windows

To make this painless in source code, new util function was added that
can return one of its arguments based on runtime OS.

+func Sieve(onUnix interface{}, onWindows interface{}) interface{}
src/reader_test.go Outdated Show resolved Hide resolved
src/util/templates.go Outdated Show resolved Hide resolved
src/util/os.go Outdated Show resolved Hide resolved
util.TemplateToString() --> templateToString()
util.OS.Sieve() --> inlined
@junegunn junegunn merged commit 88d74a1 into junegunn:master Sep 24, 2021
@junegunn
Copy link
Owner

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants