tests/modules/performance/byte-compile-lua: improve bytecode detection

Previously, to determine if a file is byte-compiled, a simple binary
file detection was used, specifically checking if it contained any null
bytes. This commit updates the check to read the file header and compare
it with a known LuaJIT header.
This commit is contained in:
Stanislav Asunkin 2025-04-29 17:22:26 +03:00
parent ddddd780e0
commit 5b47c65705
2 changed files with 26 additions and 24 deletions

View file

@ -57,17 +57,19 @@ let
}).config.home-files;
in
pkgs.runCommand "home-manager-extra-files-byte-compiling" { } ''
is_binary() {
! grep -qI . "$1"
is_byte_compiled() {
# LuaJIT bytecode header is: ESC L J version
# https://github.com/LuaJIT/LuaJIT/blob/v2.1/src/lj_bcdump.h
[[ $(head -c3 "$1") = $'\x1bLJ' ]]
}
test_byte_compiled() {
if ! is_binary "$home_files/.config/nvim/$1"; then
if ! is_byte_compiled "$home_files/.config/nvim/$1"; then
echo "File $1 is expected to be byte compiled, but it's not"
exit 1
fi
}
test_not_byte_compiled() {
if is_binary "$home_files/.config/nvim/$1"; then
if is_byte_compiled "$home_files/.config/nvim/$1"; then
echo "File $1 is not expected to be byte compiled, but it is"
exit 1
fi