move icon indicating copy to clipboard operation
move copied to clipboard

[Feature Request] Add special `test MODULE_NAME {}` block for the unit tests of the module

Open mkurnikov opened this issue 1 year ago • 0 comments

🚀 Feature Request

I propose I allow to create a separate blocks of

test ADDRESS::MODULE {

}

which have certain properties:

  1. They are the sub-scope of the original module, so scoping rules are similar to "inline module"
module mymodule {
   test mymodule {
   
   }
}

No names from inside the "test module" are accessible outside, but local imports are permitted. All private functions / fields are available inside.

  1. This "test module" can be in a separate file.

  2. (Optional, breaking change) I'd also suggest to disable creating a test functions from outside those "test modules".

Motivation

Currently, there's two ways to add tests to the module:

  1. Create a separate tests/MODULE_NAME_tests.move module, and add tests there. Problem with the approach is that tests cannot access private functions and fields of the structs. It's therefore hard to assert against the internal state.

  2. Add test function right inside the module of interest. It lacks the shortcomings of the above but increases size of the module by a lot, and this creates all kinds of problems.

mkurnikov avatar Mar 08 '23 17:03 mkurnikov