Skip to content

Commit

Permalink
Fix cfg set for integration test (#1299)
Browse files Browse the repository at this point in the history
commit-id:1d02f432

---

**Stack**:
- #1301
- #1300
- #1299⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
  • Loading branch information
maciektr authored May 10, 2024
1 parent 327bd6b commit 17a9fbd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 4 additions & 6 deletions examples/starknet_hello_world/tests/contract_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ mod tests {
use starknet::syscalls::deploy_syscall;
use traits::TryInto;

use test::test_utils::assert_eq;

use starknet_hello_world::{Balance, IBalance, IBalanceDispatcher, IBalanceDispatcherTrait};

#[test]
Expand All @@ -27,10 +25,10 @@ mod tests {
.unwrap();
let mut contract1 = IBalanceDispatcher { contract_address: address1 };

assert_eq(@contract0.get(), @100, 'contract0.get() == 100');
assert_eq(@contract1.get(), @200, 'contract1.get() == 200');
assert_eq!(@contract0.get(), @100, "contract0.get() == 100");
assert_eq!(@contract1.get(), @200, "contract1.get() == 200");
@contract1.increase(200);
assert_eq(@contract0.get(), @100, 'contract0.get() == 100');
assert_eq(@contract1.get(), @400, 'contract1.get() == 400');
assert_eq!(@contract0.get(), @100, "contract0.get() == 100");
assert_eq!(@contract1.get(), @400, "contract1.get() == 400");
}
}
6 changes: 4 additions & 2 deletions scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ fn generate_cairo_compilation_units(

// For integration tests target, rewrite package with prefixed name.
// This allows integration test code to reference main package as dependency.
let package = if package.id == member.id && is_integration_test {
let package_id_rewritten = package.id == member.id && is_integration_test;
let package = if package_id_rewritten {
Package::new(
test_package_id,
package.manifest_path().to_path_buf(),
Expand All @@ -249,7 +250,8 @@ fn generate_cairo_compilation_units(
};

let cfg_set = {
if package.id == member.id {
if package.id == member.id || package_id_rewritten {
// This is the main package.
get_cfg_with_features(
cfg_set.clone(),
&package.manifest.features,
Expand Down
16 changes: 16 additions & 0 deletions scarb/tests/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,22 @@ fn compile_test_target() {
t.child("target/dev").files(),
vec!["hello_test1.test.json", "hello_unittest.test.json",]
);

t.child("target/dev/hello_test1.test.json")
.assert_is_json::<serde_json::Value>();
let content = t.child("target/dev/hello_test1.test.json").read_to_string();
let json: serde_json::Value = serde_json::from_str(&content).unwrap();
let tests = json.get("named_tests").unwrap().as_array().unwrap();
assert_eq!(tests.len(), 1);

t.child("target/dev/hello_unittest.test.json")
.assert_is_json::<serde_json::Value>();
let content = t
.child("target/dev/hello_unittest.test.json")
.read_to_string();
let json: serde_json::Value = serde_json::from_str(&content).unwrap();
let tests = json.get("named_tests").unwrap().as_array().unwrap();
assert_eq!(tests.len(), 0);
}

#[test]
Expand Down

0 comments on commit 17a9fbd

Please sign in to comment.