Skip to content

Commit

Permalink
Fixes #62
Browse files Browse the repository at this point in the history
Go 1.9 introduces two features I was waiting for a while

- Better support for test helpers
- go list ./... doesn't list vendor go files (which is a much saner default)

This commit makes use of both features and updates documentation.

Since I was at it, I added golint to the linting process so we don't forget to document exported functions anymore (which we did in the past often enough).
  • Loading branch information
lucapette committed Sep 21, 2017
1 parent 6d308be commit ef5dc38
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.8
- 1.9
- master
install:
- make setup
Expand Down
27 changes: 14 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Contributing

We love every form of contribution. By participating to this project, you
agree to abide to the `fakedata` [code of conduct](/CODE_OF_CONDUCT.md).
We love every form of contribution. By participating to this project, you agree
to abide to the `fakedata` [code of conduct](/CODE_OF_CONDUCT.md).

## Setup your machine

Our [Makefile](/Makefile) is the entry point for most of the activities you
will run into as a contributor. To get a basic understanding of what you can
do with it, you can run:
Our [Makefile](/Makefile) is the entry point for most of the activities you will
run into as a contributor. To get a basic understanding of what you can do with
it, you can run:

```sh
$ make help
```

Which shows all the documented targets. `fakedata` is written in
[Go](https://golang.org/). Here is a list of prerequisites to
build and test the code:
[Go](https://golang.org/). Here is a list of prerequisites to build and test the
code:

* `make`
* [Go 1.8+](http://golang.org/doc/install)
* [Go 1.9+](http://golang.org/doc/install)

Clone `fakedata` from source:

Expand All @@ -39,8 +39,8 @@ A good way of making sure everything is all right is running the test suite:
$ make test
```

Please open an [issue](https://github.com/lucapette/fakedata/issues/new)
if you run into any problem.
Please open an [issue](https://github.com/lucapette/fakedata/issues/new) if you
run into any problem.

## Building and running fakedata

Expand Down Expand Up @@ -108,9 +108,10 @@ When you are satisfied with the changes, we suggest running:
$ make ci
```

This command runs all the linters and runs all the tests.
This command runs the linters and the tests the same way we run them in our CI
system.

## Submit a pull request

Push your branch to your `fakedata` fork and open a pull request against
the master branch.
Push your branch to your `fakedata` fork and open a pull request against the
master branch.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SOURCE_FILES?=$$(go list ./... | grep -v '/fakedata/vendor/')
SOURCE_FILES?=$$(go list ./...)
TEST_PATTERN?=.
TEST_OPTIONS?=

Expand All @@ -14,6 +14,7 @@ lint: ## Run all the linters
--enable=vet \
--enable=gofmt \
--enable=errcheck \
--enable=golint \
./...

ci: lint test ## Run all the tests and code checks
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ you get started.

You are expected to follow our [code of conduct](/CODE_OF_CONDUCT.md) when
interacting with the project via issues, pull requests or in any other form.
Many thanks to the awesome [contributor covenant](http://contributor-covenant.org/) initiative!
Many thanks to the awesome [contributor
covenant](http://contributor-covenant.org/) initiative!

# License

Expand Down
5 changes: 5 additions & 0 deletions integration/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newGoldenFile(t *testing.T, name string) *testFile {
}

func (tf *testFile) path() string {
tf.t.Helper()
_, filename, _, ok := runtime.Caller(0)
if !ok {
tf.t.Fatal("problems recovering caller information")
Expand All @@ -54,13 +55,15 @@ func (tf *testFile) path() string {
}

func (tf *testFile) write(content string) {
tf.t.Helper()
err := ioutil.WriteFile(tf.path(), []byte(content), 0644)
if err != nil {
tf.t.Fatalf("could not write %s: %v", tf.name, err)
}
}

func (tf *testFile) asFile() *os.File {
tf.t.Helper()
file, err := os.Open(tf.path())
if err != nil {
tf.t.Fatalf("could not open %s: %v", tf.name, err)
Expand All @@ -69,6 +72,8 @@ func (tf *testFile) asFile() *os.File {
}

func (tf *testFile) load() string {
tf.t.Helper()

content, err := ioutil.ReadFile(tf.path())
if err != nil {
tf.t.Fatalf("could not read file %s: %v", tf.name, err)
Expand Down
9 changes: 6 additions & 3 deletions pkg/fakedata/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ const fishTemplate = `
complete -c fakedata -a '%s'
`

func getTemplate(sh string) (string, error) {
switch sh {
func getTemplate(shell string) (string, error) {
switch shell {
case "bash":
return bashTemplate, nil
case "zsh":
return zshTemplate, nil
case "fish":
return fishTemplate, nil
default:
return "", fmt.Errorf("shell %s not supported. See https://github.com/lucapette/fakedata#completion", shell)
}
return "", fmt.Errorf("shell %s not supported. See https://github.com/lucapette/fakedata#completion", sh)
}

// GetCompletionFunc returns a string representing a completion function for the
// given shell. It returns an error for unsupported shell.
func GetCompletionFunc(shell string) (string, error) {
t, err := getTemplate(shell)
if err != nil {
Expand Down

0 comments on commit ef5dc38

Please sign in to comment.