Skip to content

Commit b2c6518

Browse files
authored
Rename local var for luatest from lt to t (#11)
This rock should suggest the way of writing tests and follow them itself.
1 parent 00998b7 commit b2c6518

File tree

7 files changed

+129
-129
lines changed

7 files changed

+129
-129
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,33 @@ Define tests.
2121

2222
```lua
2323
-- test/feature_test.lua
24-
local luatest = require('luatest')
25-
local t = luatest.group('feature')
24+
local t = require('luatest')
25+
local g = t.group('feature')
2626

2727
-- Define suite hooks. can be called multiple times to define hooks from different files
28-
luatest.before_suite(function() ... end)
29-
luatest.before_suite(function() ... end)
28+
t.before_suite(function() ... end)
29+
t.before_suite(function() ... end)
3030

3131
-- Hooks to run once for tests group
3232
-- This hooks run always when test class is changed.
3333
-- So it may run multiple times when --shuffle otion is used.
34-
t.before_all = function() ... end
35-
t.after_all = function() ... end
34+
g.before_all = function() ... end
35+
g.after_all = function() ... end
3636

3737
-- Hooks to run for each test in group
38-
t.setup = function() ... end
39-
t.teardown = function() ... end
38+
g.setup = function() ... end
39+
g.teardown = function() ... end
4040

4141
-- Tests. All properties with name staring with `test` are treated as test cases.
42-
t.test_example_1 = function() ... end
43-
t.test_example_n = function() ... end
42+
g.test_example_1 = function() ... end
43+
g.test_example_n = function() ... end
4444

4545
-- test/other_test.lua
46-
local luatest = require('luatest')
47-
local t = luatest.group('other')
46+
local t = require('luatest')
47+
local g = t.group('other')
4848
-- ...
49-
t.test_example_2 = function() ... end
50-
t.test_example_m = function() ... end
49+
g.test_example_2 = function() ... end
50+
g.test_example_m = function() ... end
5151
```
5252

5353
Run them.

test/capture_test.lua

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
local lt = require('luatest')
2-
local t = lt.group('capture')
1+
local t = require('luatest')
2+
local g = t.group('capture')
33

44
local Capture = require('luatest.capture')
55
local capture = Capture:new()
66

7-
t.setup = function() capture:enable() end
8-
t.teardown = function()
7+
g.setup = function() capture:enable() end
8+
g.teardown = function()
99
capture:flush()
1010
capture:disable()
1111
end
1212

13-
t.test_flush = function()
14-
lt.assertEquals(capture:flush(), {stdout = '', stderr = ''})
13+
g.test_flush = function()
14+
t.assertEquals(capture:flush(), {stdout = '', stderr = ''})
1515
io.stdout:write('test-out')
1616
io.stderr:write('test-err')
17-
lt.assertEquals(capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
18-
lt.assertEquals(capture:flush(), {stdout = '', stderr = ''})
17+
t.assertEquals(capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
18+
t.assertEquals(capture:flush(), {stdout = '', stderr = ''})
1919
end
2020

21-
t.test_flush_large_strings = function()
22-
lt.skip('no support for large strings yet')
21+
g.test_flush_large_strings = function()
22+
t.skip('no support for large strings yet')
2323
local buffer_size = 65536
2424
local out = ('a'):rep(buffer_size)
2525
local err = ('a'):rep(buffer_size + 1)
2626
io.stdout:write(out)
2727
io.stderr:write(err)
28-
lt.assertEquals(capture:flush(), {stdout = out, stderr = err})
28+
t.assertEquals(capture:flush(), {stdout = out, stderr = err})
2929
end
3030

31-
t.test_wrap = function()
31+
g.test_wrap = function()
3232
local test_capture = Capture:new()
3333
assert(not test_capture.enabled)
3434
local result = {test_capture:wrap(true, function()
@@ -37,14 +37,14 @@ t.test_wrap = function()
3737
io.stderr:write('test-err')
3838
return 'result'
3939
end)}
40-
lt.assertEquals(result, {true, 'result'})
40+
t.assertEquals(result, {true, 'result'})
4141
assert(not test_capture.enabled)
42-
lt.assertEquals(capture:flush(), {stdout = '', stderr = ''})
43-
lt.assertEquals(test_capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
44-
lt.assertEquals(capture:flush(), {stdout = '', stderr = ''})
42+
t.assertEquals(capture:flush(), {stdout = '', stderr = ''})
43+
t.assertEquals(test_capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
44+
t.assertEquals(capture:flush(), {stdout = '', stderr = ''})
4545
end
4646

47-
t.test_wrap_with_error = function()
47+
g.test_wrap_with_error = function()
4848
local test_capture = Capture:new()
4949
assert(not test_capture.enabled)
5050
local result = {test_capture:wrap(true, function()
@@ -54,18 +54,18 @@ t.test_wrap_with_error = function()
5454
invalid() -- luacheck: ignore
5555
return 'result'
5656
end)}
57-
lt.assertEquals(result, {false})
57+
t.assertEquals(result, {false})
5858
assert(not test_capture.enabled)
5959
local captured = capture:flush()
60-
lt.assertEquals(captured.stdout, '')
61-
lt.assertNotStrContains(captured.stderr, 'test-err')
62-
lt.assertStrContains(captured.stderr, "attempt to call global 'invalid'")
63-
lt.assertStrContains(captured.stderr, 'stack traceback:')
64-
lt.assertEquals(test_capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
65-
lt.assertEquals(capture:flush(), {stdout = '', stderr = ''})
60+
t.assertEquals(captured.stdout, '')
61+
t.assertNotStrContains(captured.stderr, 'test-err')
62+
t.assertStrContains(captured.stderr, "attempt to call global 'invalid'")
63+
t.assertStrContains(captured.stderr, 'stack traceback:')
64+
t.assertEquals(test_capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
65+
t.assertEquals(capture:flush(), {stdout = '', stderr = ''})
6666
end
6767

68-
t.test_wrap_nested = function()
68+
g.test_wrap_nested = function()
6969
local test_capture = Capture:new()
7070
assert(not test_capture.enabled)
7171
test_capture:wrap(true, function()
@@ -80,6 +80,6 @@ t.test_wrap_nested = function()
8080
assert(test_capture.enabled)
8181
end)
8282
assert(not test_capture.enabled)
83-
lt.assertEquals(capture:flush(), {stdout = 'test-out-2', stderr = 'test-err-2'})
84-
lt.assertEquals(test_capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
83+
t.assertEquals(capture:flush(), {stdout = 'test-out-2', stderr = 'test-err-2'})
84+
t.assertEquals(test_capture:flush(), {stdout = 'test-out', stderr = 'test-err'})
8585
end

test/capturing_test.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
local lt = require('luatest')
2-
local t = lt.group('capturing')
1+
local t = require('luatest')
2+
local g = t.group('capturing')
33

44
local helper = require('test.helper')
55
local Capture = require('luatest.capture')
66
local capture = Capture:new()
77

8-
t.setup = function() capture:enable() end
9-
t.teardown = function()
8+
g.setup = function() capture:enable() end
9+
g.teardown = function()
1010
capture:flush()
1111
capture:disable()
1212
end
1313

1414
local function assert_captured(fn)
1515
helper.run_suite(fn)
1616
local captured = capture:flush()
17-
lt.assertNotStrContains(captured.stdout, '-test-')
18-
lt.assertNotStrContains(captured.stderr, '-test-')
17+
t.assertNotStrContains(captured.stdout, '-test-')
18+
t.assertNotStrContains(captured.stderr, '-test-')
1919
end
2020

2121
local function assert_shown(fn)
2222
helper.run_suite(fn)
2323
local captured = capture:flush()
24-
lt.assertStrContains(captured.stdout, 'Captured stdout:\ntest-out')
25-
lt.assertStrContains(captured.stdout, 'Captured stderr:\ntest-err')
26-
lt.assertEquals(captured.stderr, '')
24+
t.assertStrContains(captured.stdout, 'Captured stdout:\ntest-out')
25+
t.assertStrContains(captured.stdout, 'Captured stderr:\ntest-err')
26+
t.assertEquals(captured.stderr, '')
2727
end
2828

2929
local function assert_error(fn)
30-
lt.assertEquals(helper.run_suite(fn), 1)
30+
t.assertEquals(helper.run_suite(fn), 1)
3131
local captured = capture:flush()
32-
lt.assertStrContains(captured.stderr, 'custom-error')
32+
t.assertStrContains(captured.stderr, 'custom-error')
3333
end
3434

35-
t.test_example = function()
35+
g.test_example = function()
3636
assert_captured(function(lu2)
3737
lu2.group('test').test = function()
3838
io.stdout:write('-test-')
@@ -41,7 +41,7 @@ t.test_example = function()
4141
end)
4242
end
4343

44-
t.test_example_failed = function()
44+
g.test_example_failed = function()
4545
assert_shown(function(lu2)
4646
lu2.group('test').test = function()
4747
io.stdout:write('test-out')
@@ -51,7 +51,7 @@ t.test_example_failed = function()
5151
end)
5252
end
5353

54-
t.test_example_hook = function()
54+
g.test_example_hook = function()
5555
assert_captured(function(lu2)
5656
local group = lu2.group('test')
5757
group.setup = function()
@@ -63,7 +63,7 @@ t.test_example_hook = function()
6363
end)
6464
end
6565

66-
t.test_example_hook_failed = function()
66+
g.test_example_hook_failed = function()
6767
assert_shown(function(lu2)
6868
local group = lu2.group('test')
6969
group.setup = function()
@@ -95,7 +95,7 @@ t.test_example_hook_failed = function()
9595
end
9696

9797

98-
t.test_class_hook = function()
98+
g.test_class_hook = function()
9999
assert_captured(function(lu2)
100100
local group = lu2.group('test')
101101
group.before_all = function()
@@ -115,7 +115,7 @@ t.test_class_hook = function()
115115
end)
116116
end
117117

118-
t.test_class_hook_failed = function()
118+
g.test_class_hook_failed = function()
119119
assert_error(function(lu2)
120120
local group = lu2.group('test')
121121
group.before_all = function()
@@ -137,7 +137,7 @@ t.test_class_hook_failed = function()
137137
end)
138138
end
139139

140-
t.test_suite_hook = function()
140+
g.test_suite_hook = function()
141141
assert_captured(function(lu2)
142142
local group = lu2.group('test')
143143
local hook = function()
@@ -150,7 +150,7 @@ t.test_suite_hook = function()
150150
end)
151151
end
152152

153-
t.test_suite_hook_failed = function()
153+
g.test_suite_hook_failed = function()
154154
assert_error(function(lu2)
155155
lu2.group('test').test = function() end
156156
lu2.before_suite(function()

test/helpers_test.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
local lt = require('luatest')
2-
local t = lt.group('helpers')
1+
local t = require('luatest')
2+
local g = t.group('helpers')
33

4-
local helpers = lt.helpers
4+
local helpers = t.helpers
55

6-
t.test_uuid = function()
7-
lt.assertEquals(helpers.uuid('a'), 'aaaaaaaa-0000-0000-0000-000000000000')
8-
lt.assertEquals(helpers.uuid('ab', 1), 'abababab-0000-0000-0000-000000000001')
9-
lt.assertEquals(helpers.uuid(1, 2, 3), '00000001-0002-0000-0000-000000000003')
10-
lt.assertEquals(helpers.uuid('1', '2', '3'), '11111111-2222-0000-0000-333333333333')
11-
lt.assertEquals(helpers.uuid('12', '34', '56', '78', '90'), '12121212-3434-5656-7878-909090909090')
6+
g.test_uuid = function()
7+
t.assertEquals(helpers.uuid('a'), 'aaaaaaaa-0000-0000-0000-000000000000')
8+
t.assertEquals(helpers.uuid('ab', 1), 'abababab-0000-0000-0000-000000000001')
9+
t.assertEquals(helpers.uuid(1, 2, 3), '00000001-0002-0000-0000-000000000003')
10+
t.assertEquals(helpers.uuid('1', '2', '3'), '11111111-2222-0000-0000-333333333333')
11+
t.assertEquals(helpers.uuid('12', '34', '56', '78', '90'), '12121212-3434-5656-7878-909090909090')
1212
end
1313

14-
t.test_rescuing = function()
14+
g.test_rescuing = function()
1515
local retry = 0
1616
local result = helpers.retrying({}, function(a, b)
17-
lt.assertEquals(a, 1)
18-
lt.assertEquals(b, 2)
17+
t.assertEquals(a, 1)
18+
t.assertEquals(b, 2)
1919
retry = retry + 1
2020
if (retry < 3) then
2121
error('test')
2222
end
2323
return 'result'
2424
end, 1, 2)
25-
lt.assertEquals(retry, 3)
26-
lt.assertEquals(result, result)
25+
t.assertEquals(retry, 3)
26+
t.assertEquals(result, result)
2727
end
2828

29-
t.test_rescuing_failure = function()
29+
g.test_rescuing_failure = function()
3030
local retry = 0
31-
lt.assertErrorMsgContains('test-error', function()
31+
t.assertErrorMsgContains('test-error', function()
3232
helpers.retrying({delay = 0.1, timeout = 0.5}, function(a, b)
33-
lt.assertEquals(a, 1)
34-
lt.assertEquals(b, 2)
33+
t.assertEquals(a, 1)
34+
t.assertEquals(b, 2)
3535
retry = retry + 1
3636
error('test-error')
3737
end, 1, 2)
3838
end)
39-
lt.assertAlmostEquals(retry, 6, 1)
39+
t.assertAlmostEquals(retry, 6, 1)
4040
end

0 commit comments

Comments
 (0)