-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[test_script]
for unit testing
#1832
Comments
…ation of unit testing support (#2264) This PR is a WIP that aims to address the first 3 steps in #1833. This is in anticipation of using `forc test` to support unit testing (rather than Rust integration testing) #1832. The `forc test` command remains for now, but outputs a message explaining that the command is now reserved for unit testing and links to the issues above. ## TODO - [x] Create a new `sway-test-rs` repo or similar that can be used as a `cargo generate` template. - [x] Update Rust integration testing docs in the Sway book to describe how to use the `cargo generate` command to easily add Sway integration testing to an existing Rust project. ## Follow-up - Create a `forc-test-rs` crate that re-exports and extends `fuels` with useful `forc` functionality for integration testing (e.g. re-exporting `forc_pkg::build` to ensure sway code is built and available under `out/` at the start of testing).
@adlerjohn are you happy to go with |
The motivation is that there needs to be a way to write tests that involve running a script transaction and calling one or more ABI methods, and a way to run a unit test that |
Ahhh yes, perhaps we could go with something like this?
This way we only need to check for |
Interesting alternative. I'm impartial either way, so long as there's the two options. Might be a good time to get some bikeshedding comments in! |
First steps of #1832, this adds basic awareness to the compiler for the new `#[test]` attribute. For now, we omit test functions when constructing the `ParseTree` during regular compilation (i.e. `forc build` or `forc check`) so that: 1. Programs may continue to compile even if tests do not typecheck (like Rust). 2. We don't do extra work type-checking test functions when we don't have to. 3. We don't get a bunch of dead code warnings for `#[test]` fns. Later on, I'll add an option to enable these during `forc test`, `forc check --tests`, etc. This PR doesn't enable compilation or execution of test functions just yet. This will be addressed in a following PR (see #1832). Adds a basic test that makes sure we don't provide any undesired warnings about unknown attributes or dead code.
Add a
#[test_script]
that defines a script with no input parameters and an optional output value. Only valid forcontract
s. The compiler must:.bin
file.This will be sufficient for downstream tools such as
forc test
to pick them up and automatically run them, as a first step to in-language testing.Following added by @mitchmindtree.
TODO
ParseProgram
toTyProgram
#2979.#[test]
to list of known attributes insway-core
#2980.#[test]
attribute on Sway functions.#[test]
to set of known attributes.compile
function (i.e.forc build
) to ignore all#[test]
functions. Likely best done duringconvert_parse_tree
.sway-core
to provide an alternative tocompile
calledcompile_tests
that lazily generates bytecode for each test function, treating each as an entry point.#[test]
functions).#[test]
functions as entry points for dead code analysis.#[test]
function entrypoint.forc test
command that executes the bytecode.forc check --tests
flag for use bysway-lsp
to type-check all tests (without codegen or running them).Follow-up
#[test]
feature where possible.#[test]
, rather than in E2E tests?[dev-dependencies]
table toForc.toml
.The text was updated successfully, but these errors were encountered: