Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop a shadowed testdir local to then body #342

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

muzimuzhi
Copy link
Contributor

In 8949ef3 (Improve log for failed checks with no diff files, 2023-11-06), in checkdiff(config), I mistakenly shadowed testdir inside a then body (if ... then <then body> end). This makes the assignments to that testdir local to then body, hence its new value is not used by statements after if block (see https://www.lua.org/pil/4.2.html).

Wrong way

function checkdiff(config)
  if ... then
    local testdir = testdir
    testdir = testdir .. "-" .. config
  end
  print(testdir) -- uses outer "testdir"
end

Right way

function checkdiff(config)
  local testdir = testdir
  if ... then
    testdir = testdir .. "-" .. config
  end
  print(testdir) -- uses "testdir" local to this function
end

Recently this problem was found and fixed in 761a672 (Print failures correctly when these occur in multiple configs, 2024-01-04) and 29a6933 (Exclude "build" as a config, 2024-01-08). But the fixes leave two copies of similar logic in checkdiff(config), see lines 1060-1063 and 1068-1071.

This PR removes the second copy, the one inside then body. I decided to leave the assignment to local testdir at the top of function body, rather than inside nested if blocks, to make the function's main logic a little easier to understand.

l3build/l3build-check.lua

Lines 1059 to 1072 in 0d59291

function checkdiff(config)
local testdir = testdir
if config and config ~= "build" then
testdir = testdir .. "-" .. config
end
local diff_files = ordered_filelist(testdir, "*" .. os_diffext)
if next(diff_files) then
if config then
print("Failed tests for configuration \"" .. config .. "\":")
local testdir = testdir
if config ~= "build" then
testdir = testdir .. "-" .. config
end
end

@josephwright josephwright merged commit ec6d7ae into latex3:main Jan 9, 2024
1 check passed
@muzimuzhi muzimuzhi deleted the fix/local-testdir branch January 9, 2024 18:42
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.

2 participants