Skip to content

Conversation

@ochaplashkin
Copy link

@ochaplashkin ochaplashkin commented Jan 19, 2023

Changed the work with hooks in the part of tests. The all changes were made in manual mode with automatic control of the grep utility and manual review.

What has changed

Some tests contain a legacy approach:

g.before_all = function() ... end
g.after_all = function() ... end

The logic of executing hooks will be expected and more controlled if use following approach:

g.before_all(function() ... end)
g.after_all(function() ... end)

Proof that all matches were changed

Before fixing
$ grep -r 'g.before_all =' --include='*_test.lua' . | wc -l
43
$ grep -r 'g.after_all =' --include='*_test.lua' . | wc -l
42
After fixing
$ grep -r 'g.before_all =' --include='*_test.lua' . | wc -l
0
$ grep -r 'g.after_all =' --include='*_test.lua' . | wc -l
0
$ grep -r 'g.before_each =' --include='*_test.lua' . | wc -l
0
$ grep -r 'g.after_each =' --include='*_test.lua' . | wc -l
0
$ grep -r 'g.before_test =' --include='*_test.lua' . | wc -l
0
$ grep -r 'g.after_test =' --include='*_test.lua' . | wc -l
0

Manual search using grep on different regex was done too.

Resolve #8066

@coveralls
Copy link

coveralls commented Jan 19, 2023

Coverage Status

Coverage: 85.479% (-0.01%) from 85.492% when pulling 8b95ce0 on ochaplashkin:fix-usage-before-after-all-hooks into 895cb2d
on tarantool:master
.

@ochaplashkin ochaplashkin force-pushed the fix-usage-before-after-all-hooks branch from 46d4125 to fdd5bba Compare January 19, 2023 13:46
@ochaplashkin ochaplashkin force-pushed the fix-usage-before-after-all-hooks branch 2 times, most recently from 21bcab6 to 063c6a0 Compare January 25, 2023 09:48
@ylobankov ylobankov added the full-ci Enables all tests for a pull request label Jan 25, 2023
@ochaplashkin ochaplashkin force-pushed the fix-usage-before-after-all-hooks branch from 063c6a0 to e7ec5de Compare January 25, 2023 14:12
Changed the work with hooks in the part of tests.

Legacy approach:

```
g.before_all = function() ... end
g.after_all = function() ... end
```

The logic of executing hooks will be expected and
more controlled if use following approach:

```
g.before_all(function() ... end)
g.after_all(function() ... end)
```

Resolve tarantool#8066

NO_DOC=test fix
NO_TEST=test fix
NO_CHANGELOG=test fix
@ochaplashkin ochaplashkin force-pushed the fix-usage-before-after-all-hooks branch from e7ec5de to 8b95ce0 Compare January 26, 2023 08:06
@ylobankov ylobankov added do not merge Not ready to be merged and removed full-ci Enables all tests for a pull request labels Jan 26, 2023
@ylobankov ylobankov removed the do not merge Not ready to be merged label Jan 26, 2023
@ylobankov ylobankov merged commit ed13625 into tarantool:master Jan 26, 2023
@ylobankov
Copy link
Contributor

Cherry picked to 2.10 and 1.10.

mandesero added a commit to mandesero/luatest that referenced this pull request Nov 26, 2025
Before this patch luatest accepted two ways to register hooks:

* call-style API: `group.before_all(function() ... end)`
* direct assignment: `group.before_all = function() ... end`

The second form does not work correctly with parametrized tests.
We already encountered this on the tarantool side and had to
rewrite such assignments in tarantool/tarantool#8187.

With this change luatest enforces a single, consistent way to
register hooks:

* hooks must be registered via calls like
  `before_each(function() ... end)`,
  `after_each(function() ... end)`,
  `before_all(function() ... end)`,
  `after_all(function() ... end)`,
  `before_suite(function() ... end)`,
  `after_suite(function() ... end)`,
  `before_test('name', function() ... end)` and
  `after_test('name', function() ... end)`;
* assigning to these names (e.g. `group.before_each = fn`) now
  raises an error with a clear message.

Legacy `group.setup` / `group.teardown` remain supported and are
not affected by this change.

Closes tarantool#390
mandesero added a commit to mandesero/luatest that referenced this pull request Nov 26, 2025
Before this patch luatest accepted two ways to register hooks:

* call-style API: `group.before_all(function() ... end)`
* direct assignment: `group.before_all = function() ... end`

The second form does not work correctly with parametrized tests.
We already encountered this on the tarantool side and had to
rewrite such assignments in tarantool/tarantool#8187.

With this change luatest enforces a single, consistent way to
register hooks:

* hooks must be registered via calls like
  `before_each(function() ... end)`,
  `after_each(function() ... end)`,
  `before_all(function() ... end)`,
  `after_all(function() ... end)`,
  `before_suite(function() ... end)`,
  `after_suite(function() ... end)`,
  `before_test('name', function() ... end)` and
  `after_test('name', function() ... end)`;
* assigning to these names (e.g. `group.before_each = fn`) now
  raises an error with a clear message.

Legacy `group.setup` / `group.teardown` remain supported and are
not affected by this change.

Closes tarantool#390
mandesero added a commit to mandesero/luatest that referenced this pull request Dec 1, 2025
Before this patch luatest accepted two ways to register hooks:

* call-style API: `group.before_all(function() ... end)`
* direct assignment: `group.before_all = function() ... end`

The second form does not work correctly with parametrized tests.
We already encountered this on the tarantool side and had to
rewrite such assignments in tarantool/tarantool#8187.

With this change luatest enforces a single, consistent way to
register hooks:

* hooks must be registered via calls like
  `before_each(function() ... end)`,
  `after_each(function() ... end)`,
  `before_all(function() ... end)`,
  `after_all(function() ... end)`,
  `before_suite(function() ... end)`,
  `after_suite(function() ... end)`,
  `before_test('name', function() ... end)` and
  `after_test('name', function() ... end)`;
* assigning to these names (e.g. `group.before_each = fn`) now
  raises an error with a clear message.

Legacy `group.setup` / `group.teardown` remain supported and are
not affected by this change.

Legacy `group.setup` / `group.teardown` are no longer supported;
use `before_each`/`after_each` instead.

Closes tarantool#390
mandesero added a commit to mandesero/luatest that referenced this pull request Dec 1, 2025
Before this patch luatest accepted two ways to register hooks:

* call-style API: `group.before_all(function() ... end)`
* direct assignment: `group.before_all = function() ... end`

The second form does not work correctly with parametrized tests.
We already encountered this on the tarantool side and had to
rewrite such assignments in tarantool/tarantool#8187.

With this change luatest enforces a single, consistent way to
register hooks:

* hooks must be registered via calls like
  `before_each(function() ... end)`,
  `after_each(function() ... end)`,
  `before_all(function() ... end)`,
  `after_all(function() ... end)`,
  `before_suite(function() ... end)`,
  `after_suite(function() ... end)`,
  `before_test('name', function() ... end)` and
  `after_test('name', function() ... end)`;
* assigning to these names (e.g. `group.before_each = fn`) now
  raises an error with a clear message.

Legacy `group.setup` / `group.teardown` remain supported and are
not affected by this change.

Legacy `group.setup` / `group.teardown` are no longer supported;
use `before_each`/`after_each` instead.

Closes tarantool#390
locker pushed a commit to tarantool/luatest that referenced this pull request Dec 1, 2025
Before this patch luatest accepted two ways to register hooks:

* call-style API: `group.before_all(function() ... end)`
* direct assignment: `group.before_all = function() ... end`

The second form does not work correctly with parametrized tests.
We already encountered this on the tarantool side and had to
rewrite such assignments in tarantool/tarantool#8187.

With this change luatest enforces a single, consistent way to
register hooks:

* hooks must be registered via calls like
  `before_each(function() ... end)`,
  `after_each(function() ... end)`,
  `before_all(function() ... end)`,
  `after_all(function() ... end)`,
  `before_suite(function() ... end)`,
  `after_suite(function() ... end)`,
  `before_test('name', function() ... end)` and
  `after_test('name', function() ... end)`;
* assigning to these names (e.g. `group.before_each = fn`) now
  raises an error with a clear message.

Legacy `group.setup` / `group.teardown` remain supported and are
not affected by this change.

Legacy `group.setup` / `group.teardown` are no longer supported;
use `before_each`/`after_each` instead.

Closes #390
mandesero added a commit to mandesero/tarantool that referenced this pull request Dec 1, 2025
Luatest now forbids direct hook assignment, so tests using
`g.before_all = fn`, `g.after_all = fn`, etc. must be rewritten to the
call-style API. This patch updates affected tests accordingly.

Follow-up tarantool#8187

NO_CHANGELOG=refactoring
NO_DOC=refactoring
NO_TEST=refactoring
mandesero added a commit to tarantool/test-run that referenced this pull request Dec 1, 2025
Luatest now forbids direct hook assignment, so tests using
`g.before_all = fn`, `g.after_all = fn`, etc. must be rewritten to the
call-style API. This patch updates them accordingly.

Follow-up tarantool/tarantool#8187
Follow-up luatest/luatest#390
mandesero added a commit to tarantool/test-run that referenced this pull request Dec 1, 2025
Luatest now forbids direct hook assignment, so tests using
`g.before_all = fn`, `g.after_all = fn`, etc. must be rewritten to the
call-style API. This patch updates them accordingly.

Follow-up tarantool/tarantool#8187
Follow-up tarantool/luatest#390
locker pushed a commit to tarantool/test-run that referenced this pull request Dec 2, 2025
Luatest now forbids direct hook assignment, so tests using
`g.before_all = fn`, `g.after_all = fn`, etc. must be rewritten to the
call-style API. This patch updates them accordingly.

Follow-up tarantool/tarantool#8187
Follow-up tarantool/luatest#390
mandesero added a commit to mandesero/tarantool that referenced this pull request Dec 2, 2025
Luatest now forbids direct hook assignment, so tests using
`g.before_all = fn`, `g.after_all = fn`, etc. must be rewritten to the
call-style API. This patch updates affected tests accordingly.

Follow-up tarantool#8187

NO_CHANGELOG=refactoring
NO_DOC=refactoring
NO_TEST=refactoring
locker pushed a commit that referenced this pull request Dec 2, 2025
Luatest now forbids direct hook assignment, so tests using
`g.before_all = fn`, `g.after_all = fn`, etc. must be rewritten to the
call-style API. This patch updates affected tests accordingly.

Follow-up #8187

NO_CHANGELOG=refactoring
NO_DOC=refactoring
NO_TEST=refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

luatest: incorrect g.after_all/before_all usage

3 participants