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

Replace goog.asserts and goog.testing.asserts #137

Merged
merged 9 commits into from
Oct 6, 2022

Conversation

dibenede
Copy link
Contributor

@dibenede dibenede commented Oct 5, 2022

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

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.
@dibenede dibenede requested a review from lukesandberg October 5, 2022 03:08
@dibenede dibenede self-assigned this Oct 5, 2022
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.
asserts.js Outdated Show resolved Hide resolved
asserts.js Outdated Show resolved Hide resolved
asserts.js Outdated Show resolved Hide resolved
asserts.js Outdated Show resolved Hide resolved
asserts.js Outdated Show resolved Hide resolved
binary/reader_test.js Outdated Show resolved Hide resolved
commonjs/export.js Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

debug.js Outdated Show resolved Hide resolved
maps_test.js Outdated Show resolved Hide resolved
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) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
@lukesandberg lukesandberg merged commit 828d150 into protocolbuffers:main Oct 6, 2022
@dibenede dibenede deleted the swap-asserts branch October 10, 2022 18:29
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.

Replace all goog.asserts calls with new custom asserting functions
2 participants