closes#3107
For the motivation for this PR, refer to the issue linked above.
This PR extracts all `tracing` related util functions from `forc-util`
and puts them into a dedicated `forc-tracing` crate. There is a minor
code change
[here](https://github.com/FuelLabs/sway/pull/3108/files#diff-fb650e8292a5d6bc84d8a261393ff2cabe324b5162c40ee5cf23af57ff4dcf58R161-R164)
because it is the only place that `forc-explore` uses `forc-util` (so we
can eliminate the dependency entirely), but other than that this PR is
mostly just moving code around and updating deps as required for crates
dependent on the moved `tracing` utils.
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Moves `CompileWarning` into `sway_error`. This is work towards #2734.
After this PR, we can integrate warnings into `Handler` so that it is
functionally on par with `CompileResult`, and then remains to use
`Handler` in various places, which can probably be done incrementally
over a series of PRs.
This also moves `style` and `IntegerBits` into `sway-types`. The former
is also made more "pure".
This PR achieves a couple of related things.
1. All compiler errors are moved into the common `sway-error` crate. The
`Handler` type is now also moved there, and now uses `CompileError`
instead of `ParseError`. That's also the main goal, to generalize
`Handler` to all sorts of errors, which will help solve
https://github.com/FuelLabs/sway/issues/2734 soon.
2. Using 1, we can now also emit `LexError`s into the `Handler`, so this
enables lexer recovery.
3. Lexer recovery is added for e.g., `42y8`, which fixes
https://github.com/FuelLabs/sway/issues/2865.
4. Lexer recovery is added for `'abc'` char literals, which fixes
https://github.com/FuelLabs/sway/issues/2864. The AST supports them, but
the rest of the compiler does not, so this will be useful later on, but
was good for recovery framework testing.
5. Lexer recovery is added for mismatched open/close delimiters, e.g.,
`fn foo() { )`.
6. Lexer recovery is added for unexpected closing delimiters, e.g., `fn
foo() }`.
7. Lexer recovery is added for unclosed delimiters.
8. Parser recovery is added for `let x =`, which fixes
https://github.com/FuelLabs/sway/issues/2815.
9. Misc lexer refactoring and simplifications are made.
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).
Closes https://github.com/FuelLabs/sway/issues/2375https://github.com/FuelLabs/sway/issues/2362
Related https://github.com/FuelLabs/sway/pull/2798
1. adds a global `--log-level` option.
1. changes "forc completions --shell" short form from "-s" to "-S"
because "-s" is now globally the short form of "--silent"
1. similarly, changes "forc addr2line --search-dir" short from from "-s"
to "-S"
1. adds a global `--silent` option to all forc commands and renames the
old silent mode to "terse mode".
What used to be called silent mode was not really silent; it would still
output 1 line if there were warnings or errors during the build (for
example, during CI runs).
There is still a need for a non-global option for terse mode because the
test harness runs the build commands directly (without the CLI), so
there's no way to pass the global options into the command (for example,
`forc::test::forc_check::check` which takes a `forc::cli::CheckCommand`
argument).
I can't simply set the log level to "ERROR" for the test harness
(effectively like a terse mode) because it would be applied to all tests
running in that thread, and some of the tests depend on the INFO output
to stdout to determine if the test passed. To have separate log levels
for `ir_generation` and `e2e_vm_tests`, we'd have to separate those into
separate build steps.
Closes https://github.com/FuelLabs/sway/issues/2305
Adds the `--verbose` flag to all forc commands and makes it so
`tracing::debug` logs shows when `-v` or `--verbose` is used, and
`tracing::trace` logs show when `-vv` is used.
If both `RUST_LOG` and the verbose flag are set, the verbose flag takes
precedence.
Tested with permutations of:
```
cargo run -p forc -- clean --verbose
cargo run -p forc -- init -vv
```
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
* Replace colored printlns with tracing
* ERROR only
* Revert "ERROR only"
This reverts commit 0d0320db9c.
* Make tests read from both stdout and stderr
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>