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

fix(outputter) cache all functions, use io.write not print #637

Merged
merged 1 commit into from Oct 20, 2020

Conversation

Tieske
Copy link
Member

@Tieske Tieske commented Sep 22, 2020

fixes #632
closes #633

@Tieske
Copy link
Member Author

Tieske commented Oct 18, 2020

since this is less well tested this could really use a review.

Anyone interested? @ajacksified @DorianGray @kikito @alerque

@@ -31,12 +40,14 @@ return function(options)
message = pretty.write(message)
end

print(failure:format(counter, t.name))
print(string_format(failure, counter, t.name))
Copy link
Member

@alerque alerque Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what you are doing with al these function replacements, but as I understand the original issue report and PR, the print() function itself also needs to be cached, but I don't see that happening in this PR. Am I missing something? This and a handful of following statements use print() instead of io_write(). Why do they get a pass?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more broadly; the outputters should cache the functions they use, since I replaced all usage of print, it no longer needs to be cached, since the same applies to other functions it does cache format, gsub, etc.

Copy link
Member

@alerque alerque Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I missed L9 entirely! That answers my concern.

local io_write = io.write
local io_flush = io.flush

local function print(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of confusing that methods are cached one way and used with local names (string.format()string_format()) while global functions are not (print()print()). Maybe this should be prefixed as a local function _print() and used that way throughout? (also _type etc.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't think this is a good idea I'll be fine with that too. It wouldn't be my coding style preference but it gets the job done. The rest of the PR looks okay so if you decide to dismiss this rename suggestion I'll just approve instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the point but never seen anything prefixing them with _ ? so I'd rather dismiss this one indeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see them all the time … but maybe it's mostly in my own code. And it might be a hold-over from Haskell and Rust where it is a compiler-enforced naming scheme for shadowed scope or unused values. Also note luacheck also processes _ as a way to discard a value so there is some precedent for scope delineation. And since you can't use primes like in Haskell...

In any case if you don't like it no biggy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the single "_" to ignore something is a very common Lua pattern

@Tieske Tieske merged commit 5dd0961 into master Oct 20, 2020
@Tieske Tieske deleted the outputters branch October 20, 2020 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

TAP output invalid if print function overridden
2 participants