@@ -15,6 +15,8 @@ use foundry_compilers::{
1515 flatten:: Flattener ,
1616 info:: ContractInfo ,
1717 multi:: MultiCompilerRestrictions ,
18+ preprocessor:: TestOptimizerPreprocessor ,
19+ project:: ProjectCompiler ,
1820 project_util:: * ,
1921 solc:: { Restriction , SolcRestrictions , SolcSettings } ,
2022 take_solc_installer_lock, Artifact , ConfigurableArtifacts , ExtraOutputValues , Graph , Project ,
@@ -34,6 +36,7 @@ use semver::Version;
3436use similar_asserts:: assert_eq;
3537use std:: {
3638 collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ,
39+ env,
3740 fs:: { self } ,
3841 io,
3942 path:: { Path , PathBuf , MAIN_SEPARATOR } ,
@@ -4154,3 +4157,33 @@ contract A { }
41544157 ) ;
41554158 } ) ;
41564159}
4160+
4161+ #[ test]
4162+ fn can_preprocess_constructors_and_creation_code ( ) {
4163+ let root =
4164+ canonicalize ( Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../../test-data/preprocessor" ) )
4165+ . unwrap ( ) ;
4166+
4167+ let paths = ProjectPathsConfig :: builder ( )
4168+ . sources ( root. join ( "src" ) )
4169+ . tests ( root. join ( "test" ) )
4170+ . root ( & root)
4171+ . build :: < SolcLanguage > ( )
4172+ . unwrap ( ) ;
4173+
4174+ let project = ProjectBuilder :: < SolcCompiler > :: new ( Default :: default ( ) )
4175+ . paths ( paths)
4176+ . build ( SolcCompiler :: default ( ) )
4177+ . unwrap ( ) ;
4178+
4179+ // TODO: figure out how to set root to parsing context.
4180+ let cur_dir = env:: current_dir ( ) . unwrap ( ) ;
4181+ env:: set_current_dir ( root) . unwrap ( ) ;
4182+ let compiled = ProjectCompiler :: new ( & project)
4183+ . unwrap ( )
4184+ . with_preprocessor ( TestOptimizerPreprocessor )
4185+ . compile ( )
4186+ . expect ( "failed to compile" ) ;
4187+ compiled. assert_success ( ) ;
4188+ env:: set_current_dir ( cur_dir) . unwrap ( ) ;
4189+ }
0 commit comments