Skip to content

Instantly share code, notes, and snippets.

@koduki
Created September 20, 2017 05:38
Show Gist options
  • Save koduki/4fb27b935e3e33969907c4983ee7f54e to your computer and use it in GitHub Desktop.
Save koduki/4fb27b935e3e33969907c4983ee7f54e to your computer and use it in GitHub Desktop.
Unit-Test library example for govy
module TestOperations
def test(case_name)
@case_name = case_name
r = yield
if r != nil
if @cnt_failed == nil
@cnt_failed = 0
end
@cnt_failed += 1
msg = ""
msg += @cnt_failed.to_s + ") Failure:" + "\n"
msg += r[:case] + ":" + "\n"
msg += "Expected: " + r[:expect] + "\n"
msg += " Actual: " + r[:actual] + "\n"
msg += "\n"
puts msg
end
end
def assert_equal(expect, actual)
if @cnt_assertions == nil
@cnt_assertions = 0
end
@cnt_assertions += 1
if expect != actual
{expect: expect.to_s, actual: actual.to_s, case: @case_name }
else
nil
end
end
end
class Test
extend TestOperations
def initialize
end
def self.show_report
puts @cnt_assertions.to_s + " assertions, " + @cnt_failed.to_s + " failures"
end
end
class MyTest < Test
test "tese case 001" do
assert_equal(1, 2)
end
test "tese case 002" do
assert_equal(3, 4)
end
test "tese case 003" do
assert_equal(3, 3)
end
end
MyTest.show_report
@koduki
Copy link
Author

koduki commented Sep 20, 2017

$ govy -e simple_test.gb

1) Failure:
tese case 001:
Expected: 1
  Actual: 2

2) Failure:
tese case 002:
Expected: 3
  Actual: 4

3 assertions, 2 failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment