Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: [ 2.9.4, 2.10.1, 2.11.4, 2.12.2, 2.13.1, 2.14.0 ]
version: [ 2.9.4, 2.10.1, 2.11.4, 2.12.2, 2.13.1, 2.14.0, 2.15.1 ]
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
Expand Down
12 changes: 10 additions & 2 deletions crates/cairo-coverage/tests/e2e/general.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::helpers::TestProject;
use crate::helpers::{TestProject, scarb_version};
use assert_fs::fixture::PathChild;
use semver::Version;

#[test]
fn simple() {
Expand Down Expand Up @@ -62,9 +63,16 @@ fn macros_not_included() {

#[test]
fn snforge_template() {
let file = if scarb_version() >= Version::new(2, 15, 0) {
// In cairo 2.15.0 `#[starknet::contract]` attribute generates different code.
// Hence, we have different expected output for scarb 2.15.0 and above.
"snforge_template-scarb-2.15.lcov"
} else {
"snforge_template.lcov"
};
TestProject::new("snforge_template")
.run()
.output_same_as_in_file("snforge_template.lcov");
.output_same_as_in_file(file);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
TN:
SF:{dir}/src/lib.cairo
FN:22,snforge_template::HelloStarknet::HelloStarknetImpl::get_balance
FNDA:1,snforge_template::HelloStarknet::HelloStarknetImpl::get_balance
FN:17,snforge_template::HelloStarknet::HelloStarknetImpl::increase_balance
FNDA:1,snforge_template::HelloStarknet::HelloStarknetImpl::increase_balance
FN:14,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__get_balance
FNDA:1,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__get_balance
FN:14,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__increase_balance
FNDA:1,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__increase_balance
FN:1,snforge_template::IHelloStarknetDispatcherImpl::get_balance
FNDA:1,snforge_template::IHelloStarknetDispatcherImpl::get_balance
FN:1,snforge_template::IHelloStarknetDispatcherImpl::increase_balance
FNDA:1,snforge_template::IHelloStarknetDispatcherImpl::increase_balance
FN:1,snforge_template::IHelloStarknetSafeDispatcherImpl::get_balance
FNDA:1,snforge_template::IHelloStarknetSafeDispatcherImpl::get_balance
FN:1,snforge_template::IHelloStarknetSafeDispatcherImpl::increase_balance
FNDA:1,snforge_template::IHelloStarknetSafeDispatcherImpl::increase_balance
FNF:8
FNH:8
DA:1,4
DA:14,2
DA:17,1
DA:18,1
DA:22,1
LF:5
LH:5
end_of_record
TN:
SF:{dir}/tests/test_contract.cairo
FN:11,snforge_template_integrationtest::test_contract::deploy_contract
FNDA:1,snforge_template_integrationtest::test_contract::deploy_contract
FNF:1
FNH:1
DA:11,1
DA:12,1
LF:2
LH:2
end_of_record
2 changes: 2 additions & 0 deletions crates/cairo-coverage/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod scarb_version;
mod test_project;

pub use scarb_version::scarb_version;
pub use test_project::TestProject;
38 changes: 38 additions & 0 deletions crates/cairo-coverage/tests/helpers/scarb_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use semver::Version;
use snapbox::cmd::Command as SnapboxCommand;
use std::process::Output;

pub fn scarb_version() -> Version {
let output = run_command();
let stdout = get_stdout(&output);
parse_version(&stdout)
}

fn run_command() -> Output {
SnapboxCommand::new("scarb")
.arg("-V")
.output()
.expect("failed to execute 'scarb -V'")
}

fn get_stdout(output: &Output) -> String {
if !output.status.success() {
let stderr = str::from_utf8(&output.stderr).unwrap_or("unknown error");
panic!("scarb -V failed: {stderr}");
}

str::from_utf8(&output.stdout)
.expect("scarb -V output was not valid UTF-8")
.trim()
.to_string()
}

fn parse_version(stdout: &str) -> Version {
let version_str = stdout
.split_whitespace()
.nth(1)
.expect("Unexpected output format from 'scarb -V', expected 'scarb x.y.z (hash..., date)'");

Version::parse(version_str)
.unwrap_or_else(|_| panic!("failed to parse '{version_str}' into semver"))
}
Loading