From 3e573d365545cf8003702a7ce51be43aae4f3093 Mon Sep 17 00:00:00 2001 From: Dariusz Doktorski Date: Mon, 2 Dec 2024 15:34:54 +0100 Subject: [PATCH] Fix docs snippets test for Scarb >=2.8.1 --- crates/docs/src/validation.rs | 10 ++++++++-- crates/forge/tests/e2e/common/runner.rs | 6 ------ docs/listings/hello_workspaces/Scarb.toml | 3 +++ docs/src/testing/gas-and-resource-estimation.md | 8 ++++---- docs/src/testing/running-tests.md | 8 ++++---- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 70605570a6..3c300df5cc 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -1,5 +1,5 @@ use std::{fs, io, path::Path}; - +use regex::Regex; use crate::snippet::{Snippet, SnippetConfig, SnippetType}; const EXTENSION: Option<&str> = Some("md"); @@ -23,7 +23,13 @@ pub fn extract_snippets_from_file( .name("config") .map_or_else(String::new, |m| m.as_str().to_string()); let command_match = caps.name("command")?; - let output = caps.name("output").map(|m| m.as_str().to_string()); + let output = caps.name("output").map(|m| { + let gas_re = Regex::new(r"gas: ~\d+").unwrap(); + let execution_resources_re = Regex::new(r"(steps|memory holes|builtins|syscalls): (\d+|\(.+\))").unwrap(); + + let output = gas_re.replace_all(m.as_str(), "gas: ~[..]").to_string(); + execution_resources_re.replace_all(output.as_str(), "${1}: [..]").to_string() + }); let config = if config_str.is_empty() { SnippetConfig::default() diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index bc248916b1..72a76cd405 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -88,12 +88,6 @@ pub(crate) fn setup_package_with_file_patterns( value(get_assert_macros_version().unwrap().to_string()); scarb_toml["target.starknet-contract"]["sierra"] = value(true); - if is_from_docs_listings { - scarb_toml["dev-dependencies"]["snforge_std"] - .as_table_mut() - .and_then(|snforge_std| snforge_std.remove("workspace")); - } - manifest_path.write_str(&scarb_toml.to_string()).unwrap(); // TODO (#2074): do that on .cairo.template files only diff --git a/docs/listings/hello_workspaces/Scarb.toml b/docs/listings/hello_workspaces/Scarb.toml index 8e47bbc6f5..20fec0edce 100644 --- a/docs/listings/hello_workspaces/Scarb.toml +++ b/docs/listings/hello_workspaces/Scarb.toml @@ -27,6 +27,9 @@ fibonacci = { path = "crates/fibonacci" } addition = { path = "crates/addition" } starknet = "2.7.0" +[dev-dependencies] +snforge_std.workspace = true + [workspace.dependencies] snforge_std = { path = "../../../snforge_std" } diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index c91cb15782..af5a4d6111 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -49,14 +49,14 @@ Running 2 test(s) from tests/ [PASS] hello_starknet_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~105) steps: 3405 memory holes: 22 - builtins: ([..]) - syscalls: ([..]) + builtins: (range_check: 77, pedersen: 7) + syscalls: (CallContract: 2, StorageRead: 1, Deploy: 1) [PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) steps: 4535 memory holes: 15 - builtins: ([..]) - syscalls: ([..]) + builtins: (range_check: 95, pedersen: 7) + syscalls: (CallContract: 3, StorageRead: 3, Deploy: 1, StorageWrite: 1) Running 0 test(s) from src/ Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index 0138f8f88a..63f4aa7419 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -117,14 +117,14 @@ Running 2 test(s) from tests/ [PASS] hello_starknet_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~105) steps: 3405 memory holes: 22 - builtins: ([..]) - syscalls: ([..]) + builtins: (range_check: 77, pedersen: 7) + syscalls: (CallContract: 2, StorageRead: 1, Deploy: 1) [PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) steps: 4535 memory holes: 15 - builtins: ([..]) - syscalls: ([..]) + builtins: (range_check: 95, pedersen: 7) + syscalls: (CallContract: 3, StorageRead: 3, Deploy: 1, StorageWrite: 1) Running 0 test(s) from src/ Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out