This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from suzuki-shunsuke/feat/first-pr
feat: implement basic functions
- Loading branch information
Showing
31 changed files
with
1,374 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
# the configuration file of cmdx - task runner | ||
# https://github.com/suzuki-shunsuke/cmdx | ||
tasks: | ||
- name: init | ||
short: i | ||
script: bash scripts/githook.sh | ||
description: setup git hooks | ||
usage: setup git hooks | ||
- name: coverage | ||
short: c | ||
description: test a package | ||
usage: test a package | ||
script: "bash scripts/coverage.sh {{.path}}" | ||
args: | ||
- name: path | ||
- name: test | ||
short: t | ||
description: test | ||
usage: test | ||
script: go test -v ./... -covermode=atomic | ||
- name: fmt | ||
description: format the go code | ||
usage: format the go code | ||
script: bash scripts/fmt.sh | ||
- name: vet | ||
short: v | ||
description: go vet | ||
usage: go vet | ||
script: go vet ./... | ||
- name: lint | ||
short: l | ||
description: lint the go code | ||
usage: lint the go code | ||
script: golangci-lint run | ||
- name: release | ||
short: r | ||
description: release the new version | ||
usage: release the new version | ||
script: "bash scripts/release.sh {{.version}}" | ||
args: | ||
- name: version | ||
required: true | ||
validate: | ||
- regexp: "^v\\d+\\.\\d+.\\d+(-\\d+)?$" | ||
- name: run | ||
description: tengo-tester run for test | ||
usage: tengo-tester run for test | ||
script: "go run ./cmd/tengo-tester run" |
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,45 @@ | ||
--- | ||
name: CI | ||
on: [push,pull_request] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.15.0' | ||
- run: go version | ||
- run: go mod download | ||
|
||
- name: golangci-lint | ||
run: | | ||
bash ci/install-golangci-lint.sh | ||
golangci-lint run | ||
- name: test | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | ||
run: | | ||
bash ci/test.sh tengo-tester | ||
- name: remove changes | ||
# Sometimes it is failed to release by goreleaser due to changes of go.sum | ||
run: git checkout -- . | ||
- name: fetch tags to release | ||
run: git fetch --tags | ||
- name: Unshallow | ||
run: git fetch --prune --unshallow | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run GoReleaser (skip publish) | ||
uses: goreleaser/goreleaser-action@v1 | ||
if: "! startsWith(github.ref, 'refs/tags/')" | ||
with: | ||
version: latest | ||
args: release --rm-dist --snapshot |
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,6 @@ | ||
dist/* | ||
.code-climate | ||
bin/* | ||
.git-rm-branch.yml | ||
.tengo-tester.yaml | ||
.envrc |
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,11 @@ | ||
--- | ||
linters: | ||
enable-all: true | ||
disable: | ||
- wsl | ||
- goerr113 | ||
- lll | ||
- godot | ||
- nlreturn | ||
- godox | ||
- golint |
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,12 @@ | ||
--- | ||
builds: | ||
- binary: tengo-tester | ||
main: cmd/tengo-tester/main.go | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- windows | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 |
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,2 +1,123 @@ | ||
# tengo-tester | ||
|
||
CLI to test a Tengo script | ||
|
||
## Overview | ||
|
||
tengo-tester is a CLI tool to test [Tengo](https://github.com/d5/tengo) scripts. | ||
Tengo is a fast script language for Go. | ||
|
||
We can define tests of Tengo scripts in the `tengo-tester` configuration file and test scripts by `tengo-tester run`. | ||
|
||
## Limitation | ||
|
||
https://github.com/d5/tengo/blob/master/docs/objects.md#user-object-types | ||
|
||
`tengo-tester` doesn't support the Tengo's User Extension. | ||
|
||
On the other hand, all standard library can be used. | ||
|
||
## Install | ||
|
||
Download from [GitHub Releases](https://github.com/suzuki-shunsuke/tengo-tester/releases) | ||
|
||
``` | ||
$ tengo-tester --version | ||
tengo-tester version 0.1.0 | ||
``` | ||
|
||
## Getting Started | ||
|
||
Write a Tengo script which we want to test. | ||
|
||
foo.tengo | ||
|
||
``` | ||
name := "foo" | ||
``` | ||
|
||
Generate the configuration file `.tengo-tester.yaml` by `tengo-tester init`. | ||
|
||
``` | ||
$ tengo-tester init | ||
``` | ||
|
||
Edit the configuration file. | ||
|
||
.tengo-tester.yaml | ||
|
||
```yaml | ||
--- | ||
entries: | ||
- name: main | ||
script_file: foo.tengo | ||
tests: | ||
- name: test foo | ||
var_name: name | ||
equal: foo | ||
``` | ||
Run test. | ||
``` | ||
$ tengo-tester run | ||
``` | ||
|
||
Change the configuraiton `equal` from `foo` to `fo` for the test to fail. | ||
|
||
``` | ||
$ tengo-tester run | ||
test fails | ||
entry_name: main | ||
test_name: test | ||
the value of the variable foo is unexpected (-want, +got) | ||
string( | ||
- "fo", | ||
+ "foo", | ||
) | ||
entry fails | ||
entry_name: main | ||
FATA[0000] | ||
exit status 1 | ||
``` | ||
|
||
## Configuration Reference | ||
|
||
```yaml | ||
--- | ||
entries: | ||
- name: main # entry name | ||
script_file: foo.tengo # the tested script file path | ||
params: # the parameter of the tengo script. | ||
var_name: var_value | ||
tests: | ||
- name: foo # test name | ||
script: | | ||
# tengo script to test the result | ||
# If the test fails, set the error message to the variable "err_msg". | ||
fmt := import("fmt") | ||
err_msg := "" | ||
if result.foo != "foo" { | ||
err_msg = fmt.sprintf("foo = %v, wanted foo", result.foo) | ||
} | ||
script_file: foo_test.tengo # file path to a test script | ||
var_name: foo # the variable name to be tested | ||
equal: foo # When `equal` isn't nil, the test fails if the variable isn't equal to the value of `equal`. | ||
is_nil: true # When `is_nil` is true, the test fails if the variable isn't nil. | ||
is_not_nil: true # When `is_not_nil` is true, the test fails if the variable is nil. | ||
``` | ||
## Configuration file path | ||
The configuration file path can be specified with the `--config (-c)` option. | ||
If the confgiuration file path isn't specified, the file named `.tengo-tester.yml` or `.tengo-tester.yaml` would be searched from the current directory to the root directory. | ||
|
||
## the base directory of the relative path | ||
|
||
There are some configuration which are file paths. | ||
If a file path is a relative path, the base directory of the relative path is the directory where the configuration file exists. | ||
|
||
## LICENSE | ||
|
||
[MIT](LICENSE) |
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,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
GOLANGCI_LINT_VERSION=v1.31.0 | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin" "$GOLANGCI_LINT_VERSION" |
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,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
repo_name=${1:-} | ||
if [ -z "$repo_name" ]; then | ||
echo "the repository name is required" >&2 | ||
exit 1 | ||
fi | ||
|
||
mkdir -p bin | ||
curl -L -o bin/cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 | ||
chmod a+x bin/cc-test-reporter | ||
export PATH="$PWD/bin:$PATH" | ||
bash scripts/test-code-climate.sh "$repo_name" |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/suzuki-shunsuke/tengo-tester/pkg/cli" | ||
"github.com/suzuki-shunsuke/tengo-tester/pkg/signal" | ||
) | ||
|
||
func main() { | ||
if err := core(); err != nil { | ||
logrus.Fatal(err) | ||
} | ||
} | ||
|
||
func core() error { | ||
runner := cli.Runner{} | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
go signal.Handle(os.Stderr, cancel) | ||
return runner.Run(ctx, os.Args...) | ||
} |
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 @@ | ||
cmdx test || exit 1 | ||
cmdx lint |
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,14 @@ | ||
module github.com/suzuki-shunsuke/tengo-tester | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/Masterminds/sprig v2.22.0+incompatible | ||
github.com/d5/tengo/v2 v2.6.2 | ||
github.com/google/go-cmp v0.5.2 | ||
github.com/sirupsen/logrus v1.7.0 | ||
github.com/suzuki-shunsuke/buildflow v0.6.0 | ||
github.com/suzuki-shunsuke/go-findconfig v0.1.0 | ||
github.com/urfave/cli/v2 v2.2.0 | ||
gopkg.in/yaml.v2 v2.3.0 | ||
) |
Oops, something went wrong.