Skip to content

Commit

Permalink
Fix docs snippets test for Scarb >=2.8.1 (#2742)
Browse files Browse the repository at this point in the history
<!-- Reference any GitHub issues resolved by this PR -->

## Introduced changes

<!-- A brief description of the changes -->

- Fix `e2e::docs_snippets_validation::test_docs_snippets` which failed
in the [last scheduled
run](https://github.com/foundry-rs/starknet-foundry/actions/runs/12100509808/job/33739201518)
- Replace changeable values: gas and execution resources with wildcard
`[..]` in outputs validation

---------

Co-authored-by: Franciszek Job <54181625+franciszekjob@users.noreply.github.com>
  • Loading branch information
ddoktorski and franciszekjob authored Dec 3, 2024
1 parent d513efd commit 771cf1d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
18 changes: 15 additions & 3 deletions crates/docs/src/validation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{fs, io, path::Path};

use crate::snippet::{Snippet, SnippetConfig, SnippetType};
use regex::Regex;
use std::sync::LazyLock;
use std::{fs, io, path::Path};

const EXTENSION: Option<&str> = Some("md");

Expand All @@ -23,7 +24,18 @@ 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| {
static GAS_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"gas: ~\d+").unwrap());
static EXECUTION_RESOURCES_RE: LazyLock<Regex> = LazyLock::new(|| {
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()
Expand Down
6 changes: 0 additions & 6 deletions crates/forge/tests/e2e/common/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/listings/hello_workspaces/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
8 changes: 4 additions & 4 deletions docs/src/testing/gas-and-resource-estimation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/src/testing/running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 771cf1d

Please sign in to comment.