aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

[move-formatter] Add test doc and test cases for movefmt

Open robinlzw opened this issue 1 year ago • 7 comments

Background:

A formatting tool, commonly referred to as a pretty-printer, converts the Abstract Syntax Tree (AST) generated by a parser for a specific language into a well-structured and visually appealing string of code. Currently, there have been discussions within the community regarding the need for a formatting tool specifically tailored for the Move language. However, implementing such a tool poses non-trivial challenges, resulting in the absence of a mature and user-friendly formatting solution for Move.

Motivation:

To address this gap, MoveBit aims to develop a comprehensive formatting tool for the Move language(movefmt for short). This tool is designed to be versatile, with the capability to operate within command terminal environments. It can also be easily integrated into Aptos-cli or aptos-move-analyzer.

Description:

This PR adds the test doc and test cases for movefmt. These additions aim to ensure the reliability, functionality, and robustness of the movefmt tool, thereby fostering its widespread adoption and seamless integration into various development workflows.

robinlzw avatar Dec 06 '23 10:12 robinlzw

⏱️ 1h 26m total CI duration on this PR
Job Cumulative Duration Recent Runs
rust-unit-tests 31m 🟩
windows-build 23m 🟩
rust-move-unit-coverage 19m 🟩
rust-lints 3m 🟥
general-lints 3m 🟩
check-dynamic-deps 2m 🟩
docs-lint 47s 🟩
permission-check 46s 🟥🟥🟥🟥🟥 (+8 more)
permission-check 44s 🟥🟥🟥🟥🟥 (+8 more)
permission-check 35s 🟥🟥🟥🟥🟥 (+8 more)
permission-check 33s 🟥🟥🟥🟥🟥 (+8 more)
semgrep/ci 27s 🟩
check 20s 🟥
file_change_determinator 15s 🟩
permission-check 11s 🟥🟥🟥🟥

settingsfeedbackdocs ⋅ learn more about trunk.io

trunk-io[bot] avatar Dec 06 '23 10:12 trunk-io[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 69.0%. Comparing base (8818aa2) to head (afa34cc). Report is 1001 commits behind head on main.

:exclamation: Current head afa34cc differs from pull request most recent head 6a7811d

Please upload reports for the commit 6a7811d to get more accurate results.

Additional details and impacted files
@@            Coverage Diff            @@
##             main   #11214     +/-   ##
=========================================
+ Coverage    68.7%    69.0%   +0.2%     
=========================================
  Files         758      758             
  Lines      175515   175515             
=========================================
+ Hits       120596   121111    +515     
+ Misses      54919    54404    -515     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 10 '23 03:12 codecov[bot]

There are some special comments such as //#run or //#publish, could you add test cases for them? Here is an example: bug_9717.move

rahxephon89 avatar Dec 10 '23 04:12 rahxephon89

There are some special comments such as //#run or //#publish, could you add test cases for them? Here is an example: bug_9717.move

Hello, for this feature, we have added a test case, third_party/move/tools/move-formatter/tests/formatter/fun/input6.move

robinlzw avatar Dec 11 '23 06:12 robinlzw

I just thought of two more items to cover in the test cases:

  1. address blocks:
address 0x42 {
module A {
    public fun foo() {}
}

module B {
    public fun bar() {}
}
}

Note that in the formatted version, we do not want to introduce an additional indentation within the address block. That is, the module A { line should start from column 0 without indentation.

  1. Chained methods that exceed column limit:
    let interesting_value = begin_chain().more_chaining().more_chaining().even_more_chaining().some_more_chaining().chaining_goes_on_because_it_is_so_good();

I think rust fmt does a decent job of handling such cases, we could do similar things here.

vineethk avatar Dec 19 '23 16:12 vineethk

We also need test cases at least for:

  • const declarations
  • friend declarations
  • tests with complex and multiple attributes (some examples below for inspiration)
#[test(a = @0xC0FFEE, b = @0xCAFE)] // OK. We support multiple signer arguments, but you must always provide a value for that argument
fun this_works(a: signer, b: signer) { /*some code*/ }
#[test]
#[expected_failure(vector_error, minor_status = 1, location = Self)]
fun borrow_out_of_range() {}
#[test]
#[expected_failure(abort_code = 26113, location = extensions::table)]
fun test_destroy_fails() {}

In general, look at the move book for various supported features and make sure they all are represented (phantom types are another example not yet represented).

We added 3 cases for this at: third_party/move/tools/move-formatter/tests/formatter/other/

robinlzw avatar Dec 20 '23 06:12 robinlzw

I just thought of two more items to cover in the test cases:

  1. address blocks:
address 0x42 {
module A {
    public fun foo() {}
}

module B {
    public fun bar() {}
}
}

Note that in the formatted version, we do not want to introduce an additional indentation within the address block. That is, the module A { line should start from column 0 without indentation.

  1. Chained methods that exceed column limit:
    let interesting_value = begin_chain().more_chaining().more_chaining().even_more_chaining().some_more_chaining().chaining_goes_on_because_it_is_so_good();

I think rust fmt does a decent job of handling such cases, we could do similar things here.

We added cases for this at: third_party/move/tools/move-formatter/tests/formatter/other/

We design a case about chained access that exceed column limit, but the move language currently does not support chain method calls.

robinlzw avatar Dec 20 '23 06:12 robinlzw

This issue is stale because it has been open 45 days with no activity. Remove the stale label, comment or push a commit - otherwise this will be closed in 15 days.

github-actions[bot] avatar Apr 05 '24 01:04 github-actions[bot]

This issue is stale because it has been open 45 days with no activity. Remove the stale label, comment or push a commit - otherwise this will be closed in 15 days.

github-actions[bot] avatar May 21 '24 01:05 github-actions[bot]

This issue is stale because it has been open 45 days with no activity. Remove the stale label, comment or push a commit - otherwise this will be closed in 15 days.

github-actions[bot] avatar Jul 06 '24 01:07 github-actions[bot]