Newer
Older
// then
assert!(res.is_ok());
Ok(())
})
}
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
#[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,
verbosity: VerbosityFlags::default(),
unstable_options: UnstableOptions::default(),
optimization_passes: None,
};
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(())
})
}
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
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(())
})
}
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
#[test]
fn building_contract_with_source_file_in_subfolder_must_work() {
with_new_contract_project(|manifest_path| {
// given
let path = manifest_path.directory().expect("dir must exist");
let old_lib_path = path.join(Path::new("lib.rs"));
let new_lib_path = path.join(Path::new("srcfoo")).join(Path::new("lib.rs"));
let new_dir_path = path.join(Path::new("srcfoo"));
std::fs::create_dir_all(new_dir_path).expect("creating dir must work");
std::fs::rename(old_lib_path, new_lib_path).expect("moving file must work");
let mut manifest =
Manifest::new(manifest_path.clone()).expect("creating manifest must work");
manifest
.set_lib_path("srcfoo/lib.rs")
.expect("setting lib path must work");
manifest.write(&manifest_path).expect("writing must work");
// when
let res = super::execute(
&manifest_path,
Verbosity::Default,
BuildMode::default(),
BuildArtifacts::CheckOnly,
UnstableFlags::default(),
OptimizationPasses::default(),
Default::default(),
);
// then
assert!(res.is_ok(), "building contract failed!");
Ok(())
})
}
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
#[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,
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(())
})
}