-
Notifications
You must be signed in to change notification settings - Fork 766
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 Document.initAction to fire when opening from the IDE #4582
Fix Document.initAction to fire when opening from the IDE #4582
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me. /*RUN*/
works when opening the document and when recompiling library, unit test passes, documentation is updated to match the fixed behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! some comments mostly on testing.
}; | ||
this.assert(success, "Document.new should fire Document.initAction function"); | ||
} { | ||
this.assert(false, "Cannot test Document.new behavior in a non-ScIDE session"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnitTest doesn't have a built-in mechanism for marking a test as "skip", but borrowing semantics from other test frameworks, i would expect this to pass, not fail. if we put an "assert false" in here, the test suite will always fail if you are running in an environment without the IDE, which doesn't seem right to me.
i'd suggest replacing this assertion with an empty code block with a comment like // TODO: skip this test when UnitTest has skip functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fair enough. Should there or should there not be some record of tests that were skipped, and why, in a given run? Eventually yes, I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just remembered there's an open ticket for this: #4384. i propose adding // TODO: skip
to all skipped tests so we can easily grep for them later when test skipping is implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
protect { | ||
Document.initAction = { success = true }; | ||
doc = Document.new; | ||
0.1.wait; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.1.wait
in a test is a code smell. can you justify why this is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normal way to handle asynchronicity is with a condition.hang
in the async response (initAction here). But we are testing whether the initAction fired or not. Therefore there is some reasonable expectation that the initAction may fail to fire. In that case, the Condition never unhangs and voilà, the entire test suite has ground to a halt.
This situation is impossible to test without a timeout. So, please advise what is the interface provided by the UnitTest suite for asynchronicity with timeout, and I'll very happily update (as I've been waiting years for that interface).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I've started working on a Condition:hangWithTimeout so that this might not be a problem in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't work a lot with UnitTest, but i think it's UnitTest:wait
? if that doesn't work, leaving in the 0.1.wait
is fine as long as there is a comment justifying it for anyone looking at the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, but there is #3895. Well, what to do. I'll email the dev list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you try UnitTest:wait
and see if it works here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, UnitTest:wait is better. I didn't know about that one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW fixed 10 days ago. AFAICS this is ready to go?
There was a discussion about this in the past. I remember that the result was that you can just write |
That discussion eventually rejected that solution.
|
The user may set PathName.tmp, potentially dangerous in testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! thanks
} | ||
|
||
test_open_autorun_document_runs_code { | ||
var path = Platform.defaultTempDir +/+ "autoRunTest%.scd".format(UniqueID.next), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the intent here with UniqueID.next
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think my intent was to reduce the likelihood of crashing into a leftover file in the temp directory. But UniqueID probably wouldn't work for that.
I'll just take it out.
Purpose and Motivation
Fixes #4549.
Previously,
Document.initAction = { ... }
or autorun documents took effect only when opening the document programmatically (Document.open
orDocument.new
), but these were ignored when opening the document using IDE menu commands.The simplest fix also means that autoRun documents will execute whenever recompiling the class library (if they are open). Per discussion under #4549, this seems to match the original autoRun behavior under Cocoa, and it's justifiable as an easy way to write "soft" startup code. However, the documentation inaccurately claimed that autoRun fires only when opening the document. So I updated the help file as well.
This PR touches two behaviors that are impossible to test automatically:
I've added tests for initAction and autoRun when opening a document programmatically. That's about all I think I can do.
Types of changes
To-do list