Skip to content

Commit

Permalink
Fix docs snippets test for Scarb >=2.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoktorski committed Dec 2, 2024
1 parent d513efd commit 3e573d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
10 changes: 8 additions & 2 deletions crates/docs/src/validation.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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()
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 3e573d3

Please sign in to comment.