-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add --raw-logs option for forc-test (#6528)
## Description Closes #6015 - Adds the `--raw-logs` option - Removes the `decode` option as this is now the default for `--logs` - Shortens `--pretty-print` to `--pretty` ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
9 changed files
with
166 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ uwu = ["uwuify"] | |
|
||
[dev-dependencies] | ||
completest-pty = "0.5.0" | ||
rexpect = "0.5" |
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,84 @@ | ||
use std::path::PathBuf; | ||
|
||
use rexpect::spawn; | ||
|
||
const TIMEOUT_MS: u64 = 300000; | ||
|
||
fn test_fixtures_path() -> PathBuf { | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
.join("tests") | ||
.join("fixtures") | ||
.canonicalize() | ||
.unwrap() | ||
} | ||
|
||
#[test] | ||
fn test_forc_test_decoded_logs() -> Result<(), rexpect::error::Error> { | ||
// Spawn the forc binary using cargo run | ||
let project_dir = test_fixtures_path().join("test_contract"); | ||
let mut process = spawn( | ||
&format!( | ||
"cargo run --bin forc -- test --logs --path {}", | ||
project_dir.to_string_lossy() | ||
), | ||
Some(TIMEOUT_MS), | ||
)?; | ||
|
||
// Assert that the output is correct | ||
process.exp_string(" test test_log_4")?; | ||
process.exp_string("Decoded log value: 4, log rb: 1515152261580153489")?; | ||
process.exp_string(" test test_log_2")?; | ||
process.exp_string("Decoded log value: 2, log rb: 1515152261580153489")?; | ||
|
||
process.process.exit()?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_forc_test_raw_logs() -> Result<(), rexpect::error::Error> { | ||
// Spawn the forc binary using cargo run | ||
let project_dir = test_fixtures_path().join("test_contract"); | ||
let mut process = spawn( | ||
&format!( | ||
"cargo run --bin forc -- test --raw-logs --path {}", | ||
project_dir.to_string_lossy() | ||
), | ||
Some(TIMEOUT_MS), | ||
)?; | ||
|
||
// Assert that the output is correct | ||
process.exp_string(" test test_log_4")?; | ||
process.exp_string("Raw logs:")?; | ||
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; | ||
process.exp_string(" test test_log_2")?; | ||
process.exp_string("Raw logs:")?; | ||
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; | ||
|
||
process.process.exit()?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_forc_test_both_logs() -> Result<(), rexpect::error::Error> { | ||
// Spawn the forc binary using cargo run | ||
let project_dir = test_fixtures_path().join("test_contract"); | ||
let mut process = spawn( | ||
&format!( | ||
"cargo run --bin forc -- test --logs --raw-logs --path {}", | ||
project_dir.to_string_lossy() | ||
), | ||
Some(TIMEOUT_MS), | ||
)?; | ||
|
||
// Assert that the output is correct | ||
process.exp_string(" test test_log_4")?; | ||
process.exp_string("Decoded log value: 4, log rb: 1515152261580153489")?; | ||
process.exp_string("Raw logs:")?; | ||
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; | ||
process.exp_string(" test test_log_2")?; | ||
process.exp_string("Decoded log value: 2, log rb: 1515152261580153489")?; | ||
process.exp_string("Raw logs:")?; | ||
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; | ||
process.process.exit()?; | ||
Ok(()) | ||
} |
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,2 @@ | ||
out | ||
target |
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,13 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-4D4735C41181917E" | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-4D4735C41181917E" | ||
dependencies = ["core"] | ||
|
||
[[package]] | ||
name = "test_contract" | ||
source = "member" | ||
dependencies = ["std"] |
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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "test_contract" | ||
|
||
[dependencies] | ||
std = { path = "../../../../sway-lib-std/" } |
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,23 @@ | ||
contract; | ||
|
||
abi MyContract { | ||
fn test_function() -> bool; | ||
} | ||
|
||
impl MyContract for Contract { | ||
fn test_function() -> bool { | ||
true | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_log_4() { | ||
log(4); | ||
assert(1 == 1) | ||
} | ||
|
||
#[test] | ||
fn test_log_2() { | ||
log(2); | ||
assert(1 == 1) | ||
} |