Skip to content

Commit

Permalink
Add functional tests checking outputs (#114)
Browse files Browse the repository at this point in the history
Add high level tests to ensure that gitql works as expected in an user point of view.
  • Loading branch information
Claudson Oliveira authored May 29, 2021
1 parent 008d8dd commit 4a5e764
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 20 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
submodules: true
fetch-depth: 0
path: go/src/github.com/cloudson/gitql

- name: Run tests
Expand All @@ -37,7 +39,7 @@ jobs:
./gitql -v
- name: Run function tests
run: bats -r ./tests
run: bats ./test

- uses: actions/upload-artifact@master
name: Generating artifact
Expand All @@ -63,6 +65,8 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
submodules: true
fetch-depth: 0
path: go/src/github.com/cloudson/gitql

- name: Run tests
Expand All @@ -75,7 +79,7 @@ jobs:
./gitql -v
- name: Run function tests
run: bats -r ./tests
run: bats ./test

- uses: actions/upload-artifact@master
name: Generating artifact
Expand All @@ -95,6 +99,9 @@ jobs:

- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
fetch-depth: 0
submodules: true

- name: Run tests
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ gitql
.DS_Store
.vscode*
.idea/
vendor
vendor
test/test_helper/
test/bats/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "test/bats"]
path = test/bats
url = https://github.com/bats-core/bats-core.git
[submodule "test/test_helper/bats-support"]
path = test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
4 changes: 3 additions & 1 deletion runtime/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (

"github.com/cloudson/gitql/parser"
"github.com/cloudson/gitql/utilities"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)

func walkCommits(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error) {
iter, err := repo.CommitObjects()
head, err := repo.Head()
if err != nil {
return nil, err
}
iter, err := repo.Log(&git.LogOptions{From: head.Hash()})

s := n.Child.(*parser.NodeSelect)
where := s.Where
Expand Down
1 change: 1 addition & 0 deletions test/bats
Submodule bats added at 49b377
File renamed without changes.
58 changes: 58 additions & 0 deletions test/select.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
setup() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
}

@test "Check exit code for select" {
run ./gitql 'select * from commits'
[ "$status" -eq 0 ]
}

@test "Check like for select" {
run ./gitql -f json 'select message from commits where date > "2020-10-04" and date < "2020-10-06" and message like "update"'
assert_output '[{"message":"update Dockerfile (#97)"}]'
}

@test "Check not like for select" {
run ./gitql -f json 'select message from commits where date > "2019-10-01" and date < "2019-11-01" and message not like "update"'
assert_output '[{"message":"Update How-To video with new prompts (#89)"},{"message":"Prepare v2.0.0 (#88)"},{"message":"Add support to static binaries (windows/linux amd64) (#87)"},{"message":"Add install libgit script (#86)"},{"message":"Add support to dynamic compile for mac (#85)"},{"message":"Add support to release gitql as a static file (#84)"}]'
}

@test "Check in for select" {
run ./gitql -f json 'select distinct author from commits where "Tadeu" in author and date < "2021-01-01"'
assert_output '[{"author":"Tadeu Zagallo"}]'
}

@test "Check count for select" {
run ./gitql -f json 'select count(*) from commits where date > "2019-10-09" and date < "2019-10-17"'
assert_output '[{"count":"2"}]'
}

@test "Select distinct should works" {
run ./gitql -f json 'select distinct author from commits where date > "2019-10-01" and date < "2019-11-01" order by author asc'
assert_output '[{"author":"Arumugam Jeganathan"},{"author":"Claudson Oliveira"}]'
}

@test "Select count should works" {
run ./gitql -f json 'select count(*) from commits where date < "2018-01-05"'
assert_output '[{"count":"191"}]'
}

@test "Select should works with order and limit" {
run ./gitql -f json 'select date, message from commits where date < "2020-10-01" order by date desc limit 3'
assert_output '[{"date":"2020-08-05 22:12:16","message":"Update README.md"},{"date":"2020-08-05 22:11:43","message":"Update README.md"},{"date":"2019-11-11 21:35:16","message":"Run tests on pull requests (#91)"}]'
}

# bugs to be fixed

@test "Check incorrect usage of in for select" {
skip "Should fail gracefully when using in the wrong way"
run ./gitql -f json 'select distinct author from commits where author in "Tadeu" and date < "2021-01-01"'
assert_output 'Unexpected T_IN after T_ID'
}

@test "Check incorrect json output of select" {
skip "Should not return any other field than message"
run ./gitql -f json 'select message from commits where date < "2021-05-27" order by date desc limit 3'
assert_output '[{"message":"Add smoke test about count"},{"message":"Smoke test on select discinct"},{"message":"Remove bats for windows"}]'
}
1 change: 1 addition & 0 deletions test/test_helper/bats-assert
Submodule bats-assert added at e0de84
1 change: 1 addition & 0 deletions test/test_helper/bats-support
Submodule bats-support added at d140a6
File renamed without changes.
16 changes: 0 additions & 16 deletions tests/select.bats

This file was deleted.

0 comments on commit 4a5e764

Please sign in to comment.