oxc icon indicating copy to clipboard operation
oxc copied to clipboard

Robust testing for scope analysis

Open hyf0 opened this issue 10 months ago • 0 comments

This issue is follow-up of https://github.com/oxc-project/oxc/issues/1227 and https://github.com/oxc-project/oxc/pull/2498.

Status quo

oxc currently rely on test262 and manual testing.

test262: https://github.com/oxc-project/oxc/blob/1519b9000bcdc7c43c79c8b26e194a13f7df1f1e/crates/oxc_semantic/tests/scopes.rs

manual testing: https://github.com/oxc-project/oxc/blob/e2d2ce3369bd49743cf95c095c206a92dfe0acda/tasks/coverage/src/test262.rs#L212-L235

  • test262 only ensure the all indentifier are resolved, doesn't ensure correctness.
  • Manual testing ensure correctness but only have a few cases.

Problems

With the above summary, the current scope analysis is running in half dark.

  • Can't not detect effects/changes. If someone changes scope analysis code, we could only rely on the few manual tests to ensure the correctness.
  • Dx of writing Manual tests is bad. The API could handle simple cases well. But we have to admit that, as much as we want to try make the test case simple, there's a bigger chance we need to handle complicated code. Writing manual tests for them seems impossible with current test API.

Solutions

  1. We assume the current scope analysis behaviors are correct and visualize them in snapshot testing.
  2. Visualize scope information of tests262 and also manual tests.

If someone change scope analysis code, we could review if it is correct by review changes of snapshot.

hyf0 avatar Apr 12 '24 07:04 hyf0