moon icon indicating copy to clipboard operation
moon copied to clipboard

Split `moon`'s test cases into different files

Open lynzrand opened this issue 11 months ago • 5 comments

Feature Request

Split moon's test cases that access different test directories into different files, to reduce clutter.

Summary

Motivation

It's hard to add tests for moon now, as test cases are embedded in a file more than 10kLoC. There is no direct connection between the test case names and the test folders, other than the TestDir::new call in the test function.

Detailed Description

Split moon's test cases and group by test folder, so that each test file only accesses the test folder it's in, like:

test/
  mod.rs   -- module description

  test1.in/  -- test folder
    mod.rs   -- the test itself
      -- files used in tests:
    src/
      main/
    moon.pkg.json

  test2.in/  -- another test
  ...

Related Issues

N/A

Checklist

  • [x] I have added all necessary details to make it easy for the maintainers to understand my request.

lynzrand avatar Apr 11 '25 07:04 lynzrand

Some thoughts:

  • After splitting, actually, it becomes harder to add new test cases. We should provide a helper function in xtask to generate test templates.
  • One advantage of the current pattern is that diffs are very easy to read. After splitting, diffs will be scattered across multiple files.
  • We need to consider that different test cases might reuse the same MoonBit project, for example, hello.in is reused in 7 test cases.
  • We could consider replacing expect! with expect_file! to reduce the size of the .rs test files.
  • It might be worth moving the test suite from ./crates/moon/tests/test_cases to ./tests to reduce directory nesting.

lijunchen avatar Apr 15 '25 08:04 lijunchen

After splitting, actually, it becomes harder to add new test cases. We should provide a helper function in xtask to generate test templates.

IMHO not harder than we currently do. We already copy folders to create new tests anyway.

One advantage of the current pattern is that diffs are very easy to read. After splitting, diffs will be scattered across multiple files.

Really? I often find it harder than only seeing diffs in relevant, short files ;)

We need to consider that different test cases might reuse the same MoonBit project, for example, hello.in is reused in 7 test cases.

Then all of them may reside in hello.in/mod.rs, for example

We could consider replacing expect! with expect_file! to reduce the size of the .rs test files.

Yeah, that can be a thing. But even then the file might still be too long.

lynzrand avatar Apr 15 '25 09:04 lynzrand

@lynzrand You can write a test to demonstrate the new approach. Then I can help migrate some of the tests.

cc @Young-Flash

lijunchen avatar Apr 16 '25 06:04 lijunchen

You can write a test to demonstrate the new approach.

Can I just migrate existing tests?

lynzrand avatar Apr 16 '25 06:04 lynzrand

Can I just migrate existing tests?

Yep!

lijunchen avatar Apr 16 '25 06:04 lijunchen