moonbitlang / moon

The build system and package manager for MoonBit
https://moonbitlang.github.io/moon/
GNU Affero General Public License v3.0
188 stars 17 forks source link

feat: support patch for moon test #444

Closed Young-Flash closed 2 weeks ago

Young-Flash commented 3 weeks ago

usage: moon test -p lib --patch /path/to/your/patch(_(wb)test).mbt

peter-jerry-ye-code-review[bot] commented 3 weeks ago

From the provided git diff output, it appears that several changes are being made to add support for patch files in testing functionality within the MoonBit project. Here are three observations that might be relevant from a programming perspective:

  1. Potential Typos in File Path Handling:

    • In crates/moon/src/cli/test.rs, there is a change where filter_file is being updated to include a patch file path. The line reads:
      let filter_file = cmd.file.clone().or_else(|| {
       patch.as_ref().and_then(|patch_file_path| {
           patch_file_path
               .file_name()
               .map(|it| it.to_str().unwrap().to_string())
       })
      });

      This code attempts to get the file name from the patch file path and use it as the filter file. However, the comment suggests that it should be a file path, not just the file name:

      // Path to the patch file
      #[clap(long)]
      pub patch: Option<PathBuf>,

      This discrepancy might lead to issues if the entire path is needed for context or later operations.

  2. Inconsistent Handling of Patch Files:

    • In crates/moon/tests/test_cases/mod.rs, there are multiple tests being added for different scenarios involving patch files. Each test case seems to handle patch files differently based on their suffix (.mbt, _wbtest.mbt, _test.mbt). This approach could lead to inconsistency if the handling logic is not uniformly applied across all relevant parts of the codebase. It might be beneficial to abstract the patch file handling into a common function or module to ensure consistency.
  3. Documentation Updates Needed:

    • The addition of the --patch flag in the test subcommand is not reflected in the documents. Specifically, in docs/manual-zh/src/commands.md and docs/manual/src/commands.md, the --patch flag is missing from the list of options for the test command. This omission could lead to confusion for users who might not be aware of this new feature. It's important to update the documentation to include this new flag to ensure users are informed about its existence and usage.

These observations highlight potential issues related to file path handling, consistency in code logic, and the need for documentation updates to reflect new features. Addressing these points could help maintain the quality and usability of the MoonBit project.

Young-Flash commented 2 weeks ago

closed by https://github.com/moonbitlang/moon/pull/455