build.rs 39.5 KiB
Newer Older

    #[test]
    fn contract_lib_name_different_from_package_name_must_build() {
        with_new_contract_project(|manifest_path| {
            // given
            let mut manifest =
                Manifest::new(manifest_path.clone()).expect("manifest creation failed");
            let _ = manifest
                .set_lib_name("some_lib_name")
                .expect("setting lib name failed");
            let _ = manifest
                .set_package_name("some_package_name")
                .expect("setting pacakge name failed");
            manifest
                .write(&manifest_path)
                .expect("writing manifest failed");

            // when
            let cmd = BuildCommand {
                manifest_path: Some(manifest_path.into()),
                build_artifact: BuildArtifacts::All,
                build_release: false,
                verbosity: VerbosityFlags::default(),
                unstable_options: UnstableOptions::default(),
                optimization_passes: None,
                keep_debug_symbols: false,
            };
            let res = cmd.exec().expect("build failed");

            // then
            assert_eq!(
                res.dest_wasm
                    .expect("`dest_wasm` does not exist")
                    .file_name(),
                Some(OsStr::new("some_lib_name.wasm"))
            );

            Ok(())
        })
    }
    pub fn debug_mode_must_be_compatible() {
        let _ =
            assert_debug_mode_supported(&Version::parse("3.0.0-rc4").expect("parsing must work"))
                .expect("debug mode must be compatible");
        let _ =
            assert_debug_mode_supported(&Version::parse("4.0.0-rc1").expect("parsing must work"))
                .expect("debug mode must be compatible");
        let _ = assert_debug_mode_supported(&Version::parse("5.0.0").expect("parsing must work"))
            .expect("debug mode must be compatible");
    }

    #[test]
    pub fn debug_mode_must_be_incompatible() {
        let res =
            assert_debug_mode_supported(&Version::parse("3.0.0-rc3").expect("parsing must work"))
                .expect_err("assertion must fail");
        assert_eq!(
            res.to_string(),
            "Building the contract in debug mode requires an ink! version newer than `3.0.0-rc3`!"
        );
    }

    #[test]
    fn building_template_in_debug_mode_must_work() {
        with_new_contract_project(|manifest_path| {
            // given
            let build_mode = BuildMode::Debug;

            // when
            let res = super::execute(
                &manifest_path,
                Verbosity::Default,
                build_mode,
                BuildArtifacts::All,
                UnstableFlags::default(),
                OptimizationPasses::default(),
                Default::default(),
            );

            // then
            assert!(res.is_ok(), "building template in debug mode failed!");
            Ok(())
        })
    }

    #[test]
    fn building_template_in_release_mode_must_work() {
        with_new_contract_project(|manifest_path| {
            // given
            let build_mode = BuildMode::Release;

            // when
            let res = super::execute(
                &manifest_path,
                Verbosity::Default,
                build_mode,
                BuildArtifacts::All,
                UnstableFlags::default(),
                OptimizationPasses::default(),
                Default::default(),
            );

            // then
            assert!(res.is_ok(), "building template in release mode failed!");
            Ok(())
        })
    }

    #[test]
    fn keep_debug_symbols_in_debug_mode() {
        with_new_contract_project(|manifest_path| {
            let res = super::execute(
                &manifest_path,
                Verbosity::Default,
                BuildMode::Debug,
                BuildArtifacts::CodeOnly,
                UnstableFlags::default(),
                OptimizationPasses::default(),
                true,
            )
            .expect("build failed");

            // we specified that debug symbols should be kept
            assert!(has_debug_symbols(&res.dest_wasm.unwrap()));

            Ok(())
        })
    }

    #[test]
    fn keep_debug_symbols_in_release_mode() {
        with_new_contract_project(|manifest_path| {
            let res = super::execute(
                &manifest_path,
                Verbosity::Default,
                BuildMode::Release,
                BuildArtifacts::CodeOnly,
                UnstableFlags::default(),
                OptimizationPasses::default(),
                true,
            )
            .expect("build failed");

            // we specified that debug symbols should be kept
            assert!(has_debug_symbols(&res.dest_wasm.unwrap()));

            Ok(())
        })
    }