Commit 9e117e6
committed
Improve luatest auto-requiring in
In the commit 58eae75 auto-requiring of the 'luatest'
lib was added to the `Server:eval()` function, so it was also available
in `Server:exec()`, and it was defined as `t` variable. In the process
of development we found that the following construction doesn't work due
to the upvalue error:
-- foo_bar_test.lua
local t = require('luatest')
...
g.test_foo_bar = function()
server:exec(function()
t.assert_equals(1, 1) -- upvalues exception (!)
end)
end
To fix this error we decided to make the global variable `t` that had
the 'luatest' lib already loaded. So there was no need to import the
'luatest' lib in the test files and the following example worked:
-- foo_bar_test.lua
-- local t = require('luatest') -- `t` is already defined
...
g.test_foo_bar = function()
server:exec(function()
t.assert_equals(1, 1) -- it works
end)
end:
But such an approach is not explicit enough and may mislead developers.
So it was decided to improve and extend the existing mechanism. Now we
just make the needed upvalue with the 'luatest' lib inside available in
the `Server:exec()` function via some magic. And now we can do something
like this:
-- foo_bar_test.lua
local t1 = require('luatest')
local t2 = require('luatest')
...
g.test_foo_bar_1 = function()
server:exec(function()
t1.assert_equals(1, 1) -- it works
end)
end
g.test_foo_bar_2 = function()
server:exec(function()
t2.assert_equals(1, 1) -- it works
end)
end
Unfortunately, we cannot do the same for the `Server:eval()` function
and now it becomes just a shortcut for `Server.net_box:eval()` as it
was before the first version of auto-requiring of the 'luatest' lib.
Follows up #277
In scope of #233Server:exec
1 parent 8de38b3 commit 9e117e6
File tree
6 files changed
+54
-59
lines changed- luatest
- test
6 files changed
+54
-59
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | 4 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 98 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
| 475 | + | |
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
| 483 | + | |
494 | 484 | | |
495 | 485 | | |
496 | 486 | | |
| |||
535 | 525 | | |
536 | 526 | | |
537 | 527 | | |
| 528 | + | |
538 | 529 | | |
539 | | - | |
| 530 | + | |
540 | 531 | | |
541 | 532 | | |
542 | 533 | | |
| |||
547 | 538 | | |
548 | 539 | | |
549 | 540 | | |
550 | | - | |
551 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
552 | 558 | | |
553 | 559 | | |
554 | | - | |
| 560 | + | |
555 | 561 | | |
556 | 562 | | |
557 | 563 | | |
558 | 564 | | |
559 | | - | |
560 | | - | |
| 565 | + | |
| 566 | + | |
561 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
562 | 574 | | |
563 | 575 | | |
564 | 576 | | |
565 | 577 | | |
566 | 578 | | |
567 | | - | |
| 579 | + | |
568 | 580 | | |
569 | 581 | | |
570 | 582 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
56 | | - | |
| 62 | + | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
62 | | - | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| |||
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 77 | + | |
80 | 78 | | |
81 | | - | |
82 | | - | |
83 | 79 | | |
84 | 80 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 81 | + | |
89 | 82 | | |
90 | 83 | | |
91 | 84 | | |
| |||
101 | 94 | | |
102 | 95 | | |
103 | 96 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
111 | 101 | | |
112 | 102 | | |
113 | 103 | | |
114 | | - | |
| 104 | + | |
115 | 105 | | |
116 | 106 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
13 | | - | |
| 11 | + | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
0 commit comments