-
Notifications
You must be signed in to change notification settings - Fork 72
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
Replace goog.asserts and goog.testing.asserts #137
Conversation
Closure assertions are being pruned due to the aggressiveness of the compiler's advanced optimizations. The test side is easily covered by using Jasmine's expectation system. For runtime asserts, we don't have a good replacement so we'll just copy the goog.asserts we need into a new namespace to prevent the Closure compiler from finding them.
Add a clang format guard to a particularly long, load bearing, comment we use to guide rewriting common js deps.
These were revealed to be broken by the clean test build environment. Need to remove more closure asserts.
Despite the comments, we do in fact rely on closure's COMPILED global in CommonJS tests. This variable signals some tests to skip checking data that has likely been optimized away and is used by things like debug_test.js that do name checking. Previously, this was exported by the (now dead) closure testing asserts export for CommonJS. It has now been re-homed to the testdeps.
@@ -13,3 +13,9 @@ goog.require('goog.crypt.base64'); | |||
goog.require('goog.testing.PropertyReplacer'); | |||
|
|||
exports.goog = goog; | |||
|
|||
// The COMPILED variable is set by Closure compiler to "true" when it compiles |
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.
why do we need this now?
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.
It's used in debug_test.js I believe to avoid doing dumping message names and trying to compare against something that has been optimized away.
The jspb.asserts namespace should be sufficient to prevent closure from pruning the asserts, so remove the redundant prefix from the function names.
* swap assert(foo instanceof bar) to assertInstanceof * swap many anonymous functions in tests to arrow functions * drop asserts export to commonjs since they're not needed in tests anymore * remove remaining goog.testing.TestCase require
asserts.js
Outdated
* @return {string} A copy of `str` in which each occurrence of | ||
* `%s` has been replaced an argument from `var_args`. | ||
*/ | ||
function subs(pattern, subs) { |
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.
these top level variables will need to be 'scoped' somehow.
i would just do
jspb.asserts.subs = function(...)
and tag it as a @private
otherwise we are polluting the global scope
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.
Blah, sorry missed that and doassertfailure. Removed the former since it's dead code now that we're just using Error and fixed the latter.
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.
...and missed getType. Just got it now.
doAssertFailure was mistakenly glossed over. Now namespaced and set to private. subs is dead code, so just removed it.
Closure assertions are being pruned due to the aggressiveness of the compiler's advanced optimizations. The test side is easily covered by using Jasmine's expectation system. For runtime asserts, we don't have a good replacement so we'll just copy the goog.asserts we need into a new namespace to prevent the Closure compiler from finding them.
Closes #136