diff --git a/ChangeLog.md b/ChangeLog.md index 16a776a..58b0b6e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,16 @@ # gotest.el ChangeLog +# Version 0.10.0 (01/25/2016) + +- #32: Can't install package in melpa stable +- Refactoring testing current file +- #30: Tests with only tests or examples + +# Version 0.9.0 (12/18/2015) + +- #30: Remove extra when no examples in file +- Cleanup removing unused hook + # Version 0.8.0 (11/30/2015) - #25: use -m flag for suite tests (only use -m when length > 0) (thanks IvanMalison) diff --git a/gotest.el b/gotest.el index 7c3b360..ab85ab9 100644 --- a/gotest.el +++ b/gotest.el @@ -2,10 +2,10 @@ ;; Author: Nicolas Lamirault ;; URL: https://github.com/nlamirault/gotest.el -;; Version: 0.9.0 +;; Version: 0.10.0 ;; Keywords: languages, go, tests -;; Package-Requires: ((emacs "24.3") (s "1.10.0") (f "0.18.0") (go-mode "1.3.1")) +;; Package-Requires: ((emacs "24.3") (s "1.11.0") (f "0.17.3") (go-mode "1.3.1")) ;; Copyright (C) 2014, 2015 Nicolas Lamirault @@ -321,6 +321,19 @@ For example, if the current buffer is `foo.go', the buffer for (go-test--get-current-file-data "Example")) +(defun go-test--get-current-file-testing-data () + "Regex with unit test and|or examples." + (let ((tests (go-test--get-current-file-tests)) + (examples (go-test--get-current-file-examples))) + (cond ((and (> (length tests) 0) + (> (length examples) 0)) + (s-concat tests "|" examples)) + ((= (length tests) 0) + examples) + ((= (length examples) 0) + tests)))) + + (defun go-test--arguments (args) "Make the go test command argurments using `ARGS'." (let ((opts args)) @@ -436,11 +449,7 @@ For example, if the current buffer is `foo.go', the buffer for (defun go-test-current-file () "Launch go test on the current buffer file." (interactive) - (let* ((tests (go-test--get-current-file-tests)) - (examples (go-test--get-current-file-examples)) - (data (if (> (length examples) 0) - (s-concat tests "|" examples) - tests))) + (let ((data (go-test--get-current-file-testing-data))) (if (go-test--is-gb-project) (go-test--gb-start (s-concat "-test.v=true -test.run='" data "'")) (go-test--go-test (s-concat "-run='" data "'"))))) diff --git a/test/bar_test.go b/test/bar_test.go new file mode 100644 index 0000000..a4adb76 --- /dev/null +++ b/test/bar_test.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "testing" +) + +func TestFoo(t *testing.T) { + t.Log("logFoo") +} + +func TestBar(t *testing.T) { + t.Log("logBar") +} + +func Test_Baz(t *testing.T) { + t.Log("log_Baz") +} + +func ExampleA() { + fmt.Println("Example A") + // Output: Example A +} + +func ExampleB() { + fmt.Println("Example B") + // Output: Example B +} + +func ExampleC() { + fmt.Println("Example C") + // Output: Example C +} + +func BenchmarkHello(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Println("hello") + } +} + +func BenchmarkHelloWorld(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Println("hello world") + } +} diff --git a/test/foo_test.go b/test/foo_test.go new file mode 100644 index 0000000..488b20d --- /dev/null +++ b/test/foo_test.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "testing" +) + +func ExampleA() { + fmt.Println("Example A") + // Output: Example A +} + +func ExampleB() { + fmt.Println("Example B") + // Output: Example B +} + +func ExampleC() { + fmt.Println("Example C") + // Output: Example C +} + +func BenchmarkHello(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Println("hello") + } +} + +func BenchmarkHelloWorld(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Println("hello world") + } +} diff --git a/test/gotest-test.el b/test/gotest-test.el index 905d6b5..09d338b 100644 --- a/test/gotest-test.el +++ b/test/gotest-test.el @@ -32,6 +32,12 @@ ;; (concat testsuite-dir "go_test.go") ;; "File name for testing.") + +(require 'f) +(require 's) + + + (defconst testsuite-buffer-name (f-join go-test-testsuite-dir "go_test.go") "File name for testing.") @@ -127,7 +133,7 @@ ;; when current buffer 'go.go', Test names should be found in 'go_test.go' (ert-deftest test-go-test-get-current-file-tests-other () - :tags '(find current) + :tags '(find ) (with-test-sandbox (with-current-buffer (find-file-noselect (f-join go-test-testsuite-dir "go.go")) (should (string= "TestFoo|TestBar|Test_Baz" @@ -141,6 +147,31 @@ (concat go-test-testsuite-dir "no.go")) (should-error (go-test--get-current-file-tests))))) + +(ert-deftest test-go-test-get-current-file-tests-with-only-tests () + :tags '(find current) + (with-test-sandbox + (with-current-buffer + (find-file-noselect (concat go-test-testsuite-dir "/go_test.go")) + (should (string= "TestFoo|TestBar|Test_Baz" + (go-test--get-current-file-testing-data)))))) + +(ert-deftest test-go-test-get-current-file-tests-with-only-examples () + :tags '(find current) + (with-test-sandbox + (with-current-buffer + (find-file-noselect (concat go-test-testsuite-dir "/foo_test.go")) + (should (string= "ExampleA|ExampleB|ExampleC" + (go-test--get-current-file-testing-data)))))) + +(ert-deftest test-go-test-get-current-file-tests () + :tags '(find current) + (with-test-sandbox + (with-current-buffer + (find-file-noselect (concat go-test-testsuite-dir "/bar_test.go")) + (should (string= "TestFoo|TestBar|Test_Baz|ExampleA|ExampleB|ExampleC" + (go-test--get-current-file-testing-data)))))) + ;; Error Regexp ;; (ert-deftest test-go-test-compilation-error-regexp-matches () diff --git a/test/gotest-version-test.el b/test/gotest-version-test.el index cf8904a..2ba04d1 100644 --- a/test/gotest-version-test.el +++ b/test/gotest-version-test.el @@ -28,7 +28,7 @@ :expected-result (if (executable-find "cask") :passed :failed) (let* ((cask-version (car (process-lines "cask" "version")))) (message "gotest.el Cask version: %s" cask-version) - (should (string= "0.9.0" cask-version)))) + (should (string= "0.10.0" cask-version)))) (provide 'gotest-version-test) diff --git a/var/bar_test.go b/var/bar_test.go new file mode 100644 index 0000000..095673c --- /dev/null +++ b/var/bar_test.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "testing" +) + +func TestA(t *testing.T) { + fmt.Println("test a") +} + +func TestB(t *testing.T) { + fmt.Println("test b") +} + +func TestAB(t *testing.T) { + fmt.Println("test ab") +} + +func BenchmarkHello(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Println("hello") + } +} + +func BenchmarkHelloWorld(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Println("hello world") + } +}