forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sway unit test (i.e.
#[test]
fn) compilation (FuelLabs#2985)
OK, this should be good to go! ## Highlights - Adds support for multiple entry points to IR. Adds a tests for serializing entry functions to/from IR. - Enables ASM generation for libraries (to support test function entry points). - Track entry points through ASM generation so we can return entry point metadata as a part of the compilation result. This doesn't affect ASM generation, but allows tools using `sway-core` as a library to work with different entry points. - Updated E2E test harness with a new test category "UnitTestsPass". - Added E2E tests with multiple unit tests for each type of Sway program (library, script, predicate, contract). - Gets `forc test` working with pretty output! Here's the output from the new `lib_multi_test`: ![Screenshot from 2022-11-03 19-00-57](https://user-images.githubusercontent.com/4587373/199700362-ba32f90d-1f0f-4f76-bf89-b191de9589af.png) ## Test running implementation Currently, it seems like there's no publicly accessible approach to execute a script directly from a custom entry point. As a result, for each test, we patch the bytecode with a `JI` instruction that jumps from after the data section setup to the test's entry point. This is a bit hairy, but works for now! As a follow-up, we may want to consider adding support upstream in `fuel-vm` for executing scripts directly from a given entry point. Even if this was only exposed from the interpreter API, this would make the `forc-test` implementation quite a bit cleaner and avoid the need to patch the bytecode. Alternatively, when building projects we could return more metadata along with the compiled output (whether in memory or bytecode header) to indicate how to work with different entry points in a more reliable manner (rather than the magic const offset currently used in `forc-test`). # TODO - [x] Add `include_tests` flag to `BuildConfig`, allowing `forc` to trigger compilation of test functions. - [x] Include `#[test]` fns as entry points within dead code analysis. - [x] IR and ASM generation for test entry points. - [x] Add `forc build --tests`. - [x] Add `forc test`. - [x] Always include test fns in `TyProgram` (for DCA), but omit from IR if not building tests. - [x] Work out how to iterate over different entry points during `forc test`. - [x] Only generate tests for top-level "members" (not all dependencies). ### Follow-up: - FuelLabs#3260 - FuelLabs#3261 - FuelLabs#3262 - FuelLabs#3263 - FuelLabs#3264 - FuelLabs#3265 - FuelLabs#3266 - FuelLabs#3267 - FuelLabs#3268 Closes FuelLabs#1832.
- Loading branch information
1 parent
3805a6f
commit 5f29c66
Showing
54 changed files
with
920 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "forc-test" | ||
version = "0.30.0" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
edition = "2021" | ||
homepage = "https://fuel.network/" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/FuelLabs/sway" | ||
description = "A library for building and running Sway unit tests within Forc packages." | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
forc-pkg = { version = "0.30.0", path = "../forc-pkg" } | ||
fuel-tx = { version = "0.23", features = ["builder"] } | ||
fuel-vm = { version = "0.22", features = ["random"] } | ||
rand = "0.8" | ||
sway-core = { version = "0.30.0", path = "../sway-core" } |
Oops, something went wrong.