Commit graph

3 commits

Author SHA1 Message Date
Vadim Peretokin
1dfd5c4605
infrastructure: release resources in test fixture destructors (#9522)
#### Brief overview of PR changes/additions
- Convert the raw owning `LuaInterface*` member in the
`TLuaInterfaceTest` and `TVariableEditorTest` Qt-Test fixtures to
`std::unique_ptr<LuaInterface>` so the fixture's destructor frees it.
- `TLuaInterfaceTest` also stops allocating the interface (and a
`lua_State`) twice: members now init to `nullptr`/empty and are
allocated only in `init()`; `cleanup()` resets the interface before
closing the `lua_State`.

#### Motivation for adding to Mudlet
Keeps the test suite leak-clean and clears static-analysis warnings, per
CLAUDE.md's "smart pointers for non-Qt classes".

#### Other info (issues closed, discussion etc)
- Clears 2 CodeQL `cpp/resource-not-released-in-destructor` warnings
(`test/TVariableEditorTest.cpp`, `test/TLuaInterfaceTest.cpp`).
- Also removes a real runtime leak in `TLuaInterfaceTest`: the old
fixture never deleted the `interface` and double-allocated it
(construction + `init()`), leaking a `LuaInterface` per test plus a
construction-time `lua_State`/`LuaInterface`. Verified gone under
LeakSanitizer (old binary leaked, new binary is leak-clean;
`TVariableEditorTest` already deleted its interface so for it this is
modernization).

**Test case:** Build and run `ctest -R
'TLuaInterfaceTest|TVariableEditorTest'` - both pass (TLuaInterfaceTest
4/4, TVariableEditorTest 96 passed/13 skipped). Optionally run
`./test/TLuaInterfaceTest` with `ASAN_OPTIONS=detect_leaks=1` to confirm
no leaks are reported.
2026-07-29 13:45:22 +02:00
Stephen Lyons
033db9553c
Fix: ensure we include the right Lua header files (#7842)
#### Brief overview of PR changes/additions
For Windows builds modify the `#include` lines for Lua header files to
specify the 5.1 version. Also accommodate some changes in our CI build
environment:
* For some reason (maybe because of a more modern linker) we need to
specify the original PCRE library with `-lpcre` rather than `-lpcre-1` -
the exact cause of this is not clear but thanks to @jmckisson for
finding it (and using it in his attempt to solve the same problems this
PR is doing).
* It seems the Window building is now being done in the `C:` drive
rather than the previous `D:` one, so a tweak to clean the colon
containing file-system root specifier to the alternative that
MSYS2+Mingw-w64 uses which instead uses a (POSIX) `/` root directory
followed by a single lower-case letter to specify the drive needs to be
extended to handle both drives. This is because the scripts use `rsync`
and that treats any `:` as the separator between host and path and gets
confused when it sees a "Windows" path containing it!

#### Motivation for adding to Mudlet
The default version - and the one needed for some packages like Luarocks
is a 5.4 one - and that includes header files in the "default" `include`
directory. So the headers that get pulled in are the wrong ones, which
fail to work as they are not compatible with Lua 5.1; to get the 5.1
instead I believe we need to explicitly include the version specific
sub-directory in the `#include` lines.

Other tweaks are also needed "to get things working nowadays."

#### Other info (issues closed, discussion etc)
This should be simpler to do than what is being attempted by #7841.

---------

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2025-05-17 22:34:05 +01:00
Chris Mitchell
9f23e99e00
Add tests for variable interface (#5141)
* Cleanup

* Fix settings for linux override

* Fix debug mode

* Commit env template

* Reduce default core count

* Some initial work on lua interface tests

* Fix lua tests

* Fix import in lua interface

* Fix lua state reference

* Fix tests

* Validate var name is correct

* Update includes

* Some lint fixes

* Remove unused code

* Add copyright bit

* lint fix

* nolint
2021-04-17 14:48:23 -04:00