diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 372cb04..57ae8a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: | diff --git a/.gitignore b/.gitignore index 657a7eb..dc6c586 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ gitql .DS_Store .vscode* .idea/ -vendor \ No newline at end of file +vendor +test/test_helper/ +test/bats/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7efcb4 --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/runtime/commits.go b/runtime/commits.go index fb25356..70f6126 100644 --- a/runtime/commits.go +++ b/runtime/commits.go @@ -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 diff --git a/test/bats b/test/bats new file mode 160000 index 0000000..49b377a --- /dev/null +++ b/test/bats @@ -0,0 +1 @@ +Subproject commit 49b377a751e6f9379abfdfb3dfa3aafabd8495a1 diff --git a/tests/options.bats b/test/options.bats similarity index 100% rename from tests/options.bats rename to test/options.bats diff --git a/test/select.bats b/test/select.bats new file mode 100644 index 0000000..56775d0 --- /dev/null +++ b/test/select.bats @@ -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"}]' +} \ No newline at end of file diff --git a/test/test_helper/bats-assert b/test/test_helper/bats-assert new file mode 160000 index 0000000..e0de84e --- /dev/null +++ b/test/test_helper/bats-assert @@ -0,0 +1 @@ +Subproject commit e0de84e9c011223e7f88b7ccf1c929f4327097ba diff --git a/test/test_helper/bats-support b/test/test_helper/bats-support new file mode 160000 index 0000000..d140a65 --- /dev/null +++ b/test/test_helper/bats-support @@ -0,0 +1 @@ +Subproject commit d140a65044b2d6810381935ae7f0c94c7023c8c3 diff --git a/tests/use.bats b/test/use.bats similarity index 100% rename from tests/use.bats rename to test/use.bats diff --git a/tests/select.bats b/tests/select.bats deleted file mode 100644 index af79649..0000000 --- a/tests/select.bats +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -@test "Check exit code for select" { - result="$(./gitql 'select * from commits')" - [ "$?" == "0" ] -} - -@test "Select discting should work" { - run ./gitql 'select distinct author from commits' - [ "$status" -eq 0 ] -} - -@test "Select count should work" { - run ./gitql 'select count(*) from commits' - [ "$status" -eq 0 ] -} \ No newline at end of file