@@ -6,9 +6,10 @@ use camino::Utf8PathBuf;
66use forge:: CAIRO_EDITION ;
77use indoc:: { formatdoc, indoc} ;
88use shared:: test_utils:: output_assert:: assert_stdout_contains;
9- use std:: { env, fs, path:: Path , str:: FromStr } ;
10- use test_utils:: tempdir_with_tool_versions;
11- use toml_edit:: { value, DocumentMut , Item } ;
9+ use snapbox:: assert_matches;
10+ use std:: { fs, path:: Path , str:: FromStr } ;
11+ use test_utils:: { get_local_snforge_std_absolute_path, tempdir_with_tool_versions} ;
12+ use toml_edit:: { value, DocumentMut , Formatted , InlineTable , Item , Value } ;
1213
1314#[ test]
1415fn simple_package ( ) {
@@ -655,90 +656,143 @@ fn with_exit_first_flag() {
655656 ) ;
656657}
657658
658- // TODO (2274): This test has inherently flawed logic, needs to be re-written
659- #[ ignore]
660659#[ test]
661660fn init_new_project_test ( ) {
662661 let temp = tempdir_with_tool_versions ( ) . unwrap ( ) ;
663662
664- runner ( & temp) . args ( [ "init" , "test_name" ] ) . assert ( ) . success ( ) ;
665- let manifest_path = temp. child ( "test_name/Scarb.toml" ) ;
663+ runner ( & temp)
664+ . args ( [ "init" , "test_name" ] )
665+ . env ( "DEV_DISABLE_SNFORGE_STD_DEPENDENCY" , "true" )
666+ . assert ( )
667+ . success ( ) ;
668+
669+ let manifest_path = temp. join ( "test_name/Scarb.toml" ) ;
670+ let scarb_toml = std:: fs:: read_to_string ( manifest_path. clone ( ) ) . unwrap ( ) ;
666671
667- let generated_toml = std:: fs:: read_to_string ( manifest_path. path ( ) ) . unwrap ( ) ;
668- let version = env ! ( "CARGO_PKG_VERSION" ) ;
669- let expected_toml = formatdoc ! (
672+ let expected = formatdoc ! (
670673 r#"
671674 [package]
672675 name = "test_name"
673676 version = "0.1.0"
674- edition = "{}"
677+ edition = "{CAIRO_EDITION }"
675678
676679 # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html
677680
678681 [dependencies]
679- starknet = "2.6.4 "
682+ starknet = "[..] "
680683
681684 [dev-dependencies]
682- snforge_std = {{ git = "https://github.com/foundry-rs/starknet-foundry", tag = "v{}" }}
683685
684686 [[target.starknet-contract]]
685687 sierra = true
686688
687689 [scripts]
688690 test = "snforge test"
689- "# ,
690- CAIRO_EDITION ,
691- version,
691+ "#
692692 ) ;
693693
694- assert_eq ! ( generated_toml , expected_toml ) ;
694+ assert_matches ( & expected , & scarb_toml ) ;
695695
696- let remote_url = get_remote_url ( ) ;
697- let branch = get_current_branch ( ) ;
698- manifest_path
699- . write_str ( & formatdoc ! (
700- r#"
701- [package]
702- name = "test_name"
703- version = "0.1.0"
696+ let mut scarb_toml = DocumentMut :: from_str ( & scarb_toml) . unwrap ( ) ;
704697
705- [[target.starknet-contract]]
698+ let dependencies = scarb_toml
699+ . get_mut ( "dev-dependencies" )
700+ . unwrap ( )
701+ . as_table_mut ( )
702+ . unwrap ( ) ;
706703
707- [dependencies]
708- starknet = "2.5.4"
704+ let local_snforge_std = get_local_snforge_std_absolute_path ( )
705+ . unwrap ( )
706+ . to_str ( )
707+ . unwrap ( )
708+ . to_string ( ) ;
709709
710- [dev-dependencies]
711- snforge_std = {{ git = "https://github.com/{}", branch = "{}" }}
712- "# ,
713- remote_url ,
714- branch
715- ) )
716- . unwrap ( ) ;
710+ let mut snforge_std = InlineTable :: new ( ) ;
711+ snforge_std. insert ( "path" , Value :: String ( Formatted :: new ( local_snforge_std ) ) ) ;
712+
713+ dependencies . remove ( "snforge_std" ) ;
714+ dependencies . insert ( "snforge_std" , Item :: Value ( Value :: InlineTable ( snforge_std ) ) ) ;
715+
716+ std :: fs :: write ( manifest_path , scarb_toml . to_string ( ) ) . unwrap ( ) ;
717717
718- // Check if template works with current version of snforge_std
719718 let output = test_runner ( & temp)
720719 . current_dir ( temp. child ( Path :: new ( "test_name" ) ) )
721720 . assert ( )
722721 . success ( ) ;
723- assert_stdout_contains (
724- output,
725- formatdoc ! (
726- r"
727- [..]Updating git repository https://github.com/{}
722+
723+ let expected = indoc ! (
724+ r"
728725 [..]Compiling test_name v0.1.0[..]
729726 [..]Finished[..]
730727
728+ Collected 2 test(s) from test_name package
729+ Running 0 test(s) from src/
730+ Running 2 test(s) from tests/
731+ [PASS] test_name_integrationtest::test_contract::test_increase_balance [..]
732+ [PASS] test_name_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value [..]
733+ Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out
734+ "
735+ ) ;
736+
737+ assert_stdout_contains ( output, expected) ;
738+ }
739+
740+ #[ test]
741+ #[ cfg( feature = "smoke" ) ]
742+ fn test_init_project_with_custom_snforge_dependency_git ( ) {
743+ let temp = tempdir_with_tool_versions ( ) . unwrap ( ) ;
744+
745+ runner ( & temp)
746+ . args ( [ "init" , "test_name" ] )
747+ . env ( "DEV_DISABLE_SNFORGE_STD_DEPENDENCY" , "true" )
748+ . assert ( )
749+ . success ( ) ;
750+
751+ let manifest_path = temp. child ( "test_name/Scarb.toml" ) ;
752+
753+ let scarb_toml = std:: fs:: read_to_string ( manifest_path. path ( ) ) . unwrap ( ) ;
754+ let mut scarb_toml = DocumentMut :: from_str ( & scarb_toml) . unwrap ( ) ;
755+
756+ let dependencies = scarb_toml
757+ . get_mut ( "dev-dependencies" )
758+ . unwrap ( )
759+ . as_table_mut ( )
760+ . unwrap ( ) ;
761+
762+ let branch = get_current_branch ( ) ;
763+ let remote_url = format ! ( "https://github.com/{}" , get_remote_url( ) ) ;
764+
765+ let mut snforge_std = InlineTable :: new ( ) ;
766+ snforge_std. insert ( "git" , Value :: String ( Formatted :: new ( remote_url. clone ( ) ) ) ) ;
767+ snforge_std. insert ( "branch" , Value :: String ( Formatted :: new ( branch) ) ) ;
768+
769+ dependencies. remove ( "snforge_std" ) ;
770+ dependencies. insert ( "snforge_std" , Item :: Value ( Value :: InlineTable ( snforge_std) ) ) ;
771+
772+ std:: fs:: write ( manifest_path. path ( ) , scarb_toml. to_string ( ) ) . unwrap ( ) ;
773+
774+ let output = test_runner ( & temp)
775+ . current_dir ( temp. child ( Path :: new ( "test_name" ) ) )
776+ . assert ( )
777+ . success ( ) ;
778+
779+ let expected = formatdoc ! (
780+ r"
781+ [..]Updating git repository {}
782+ [..]Compiling test_name v0.1.0[..]
783+ [..]Finished[..]
731784
732785 Collected 2 test(s) from test_name package
733786 Running 0 test(s) from src/
734787 Running 2 test(s) from tests/
735788 [PASS] test_name_integrationtest::test_contract::test_increase_balance [..]
736789 [PASS] test_name_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value [..]
737790 Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out
738- " ,
739- remote_url. trim_end_matches( ".git" )
740- ) ,
791+ " ,
792+ remote_url. trim_end_matches( ".git" )
741793 ) ;
794+
795+ assert_stdout_contains ( output, expected) ;
742796}
743797
744798#[ test]
0 commit comments