Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs snippets test for Scarb >=2.8.1 #2742

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading