|
16 | 16 | require_relative "./test_utils/XcodeprojMock.rb"
|
17 | 17 | require_relative "./test_utils/XcodebuildMock.rb"
|
18 | 18 | require_relative "./test_utils/SpecMock.rb"
|
| 19 | +require_relative "./test_utils/InstallerMock.rb" |
19 | 20 |
|
20 | 21 | class UtilsTests < Test::Unit::TestCase
|
21 | 22 | def setup
|
@@ -1008,6 +1009,78 @@ def test_addDependencies_whenSubspecsAndHeaderSearchPathAndVersionWithAdditional
|
1008 | 1009 | assert_equal(spec.to_hash["pod_target_xcconfig"], {
|
1009 | 1010 | "HEADER_SEARCH_PATHS" => expected_search_paths})
|
1010 | 1011 | end
|
| 1012 | + |
| 1013 | + def test_add_flag_to_map_with_inheritance_whenUsedWithBuildConfigBuildSettings |
| 1014 | + # Arrange |
| 1015 | + empty_config = BuildConfigurationMock.new("EmptyConfig") |
| 1016 | + initialized_config = BuildConfigurationMock.new("InitializedConfig", { |
| 1017 | + "OTHER_CPLUSPLUSFLAGS" => "INIT_FLAG" |
| 1018 | + }) |
| 1019 | + twiceProcessed_config = BuildConfigurationMock.new("TwiceProcessedConfig"); |
| 1020 | + test_flag = " -DTEST_FLAG=1" |
| 1021 | + |
| 1022 | + # Act |
| 1023 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(empty_config.build_settings, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1024 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(initialized_config.build_settings, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1025 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(twiceProcessed_config.build_settings, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1026 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(twiceProcessed_config.build_settings, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1027 | + |
| 1028 | + # Assert |
| 1029 | + assert_equal("$(inherited)" + test_flag, empty_config.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1030 | + assert_equal("$(inherited) INIT_FLAG" + test_flag, initialized_config.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1031 | + assert_equal("$(inherited)" + test_flag, twiceProcessed_config.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1032 | + end |
| 1033 | + |
| 1034 | + def test_add_flag_to_map_with_inheritance_whenUsedWithXCConfigAttributes |
| 1035 | + # Arrange |
| 1036 | + empty_xcconfig = XCConfigMock.new("EmptyConfig") |
| 1037 | + initialized_xcconfig = XCConfigMock.new("InitializedConfig", attributes: { |
| 1038 | + "OTHER_CPLUSPLUSFLAGS" => "INIT_FLAG" |
| 1039 | + }) |
| 1040 | + twiceProcessed_xcconfig = XCConfigMock.new("TwiceProcessedConfig"); |
| 1041 | + test_flag = " -DTEST_FLAG=1" |
| 1042 | + |
| 1043 | + # Act |
| 1044 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(empty_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1045 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(initialized_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1046 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(twiceProcessed_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1047 | + ReactNativePodsUtils.add_flag_to_map_with_inheritance(twiceProcessed_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) |
| 1048 | + |
| 1049 | + # Assert |
| 1050 | + assert_equal("$(inherited)" + test_flag, empty_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"]) |
| 1051 | + assert_equal("$(inherited) INIT_FLAG" + test_flag, initialized_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"]) |
| 1052 | + assert_equal("$(inherited)" + test_flag, twiceProcessed_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"]) |
| 1053 | + end |
| 1054 | + |
| 1055 | + def test_add_ndebug_flag_to_pods_in_release |
| 1056 | + # Arrange |
| 1057 | + xcconfig = XCConfigMock.new("Config") |
| 1058 | + default_debug_config = BuildConfigurationMock.new("Debug") |
| 1059 | + default_release_config = BuildConfigurationMock.new("Release") |
| 1060 | + custom_debug_config1 = BuildConfigurationMock.new("CustomDebug") |
| 1061 | + custom_debug_config2 = BuildConfigurationMock.new("Custom") |
| 1062 | + custom_release_config1 = BuildConfigurationMock.new("CustomRelease") |
| 1063 | + custom_release_config2 = BuildConfigurationMock.new("Production") |
| 1064 | + |
| 1065 | + installer = prepare_installer_for_cpp_flags( |
| 1066 | + [ xcconfig ], |
| 1067 | + { |
| 1068 | + "Default" => [ default_debug_config, default_release_config ], |
| 1069 | + "Custom1" => [ custom_debug_config1, custom_release_config1 ], |
| 1070 | + "Custom2" => [ custom_debug_config2, custom_release_config2 ] |
| 1071 | + } |
| 1072 | + ) |
| 1073 | + # Act |
| 1074 | + ReactNativePodsUtils.add_ndebug_flag_to_pods_in_release(installer) |
| 1075 | + |
| 1076 | + # Assert |
| 1077 | + assert_equal(nil, default_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1078 | + assert_equal("$(inherited) -DNDEBUG", default_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1079 | + assert_equal(nil, custom_debug_config1.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1080 | + assert_equal("$(inherited) -DNDEBUG", custom_release_config1.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1081 | + assert_equal(nil, custom_debug_config2.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1082 | + assert_equal("$(inherited) -DNDEBUG", custom_release_config2.build_settings["OTHER_CPLUSPLUSFLAGS"]) |
| 1083 | + end |
1011 | 1084 | end
|
1012 | 1085 |
|
1013 | 1086 | # ===== #
|
@@ -1050,3 +1123,31 @@ def prepare_Code_Signing_build_configuration(name, param)
|
1050 | 1123 | "CODE_SIGNING_ALLOWED" => param
|
1051 | 1124 | })
|
1052 | 1125 | end
|
| 1126 | + |
| 1127 | +def prepare_pod_target_installation_results_mock(name, configs) |
| 1128 | + target = TargetMock.new(name, configs) |
| 1129 | + return TargetInstallationResultMock.new(target, target) |
| 1130 | +end |
| 1131 | + |
| 1132 | +def prepare_installer_for_cpp_flags(xcconfigs, build_configs) |
| 1133 | + xcconfigs_map = {} |
| 1134 | + xcconfigs.each do |config| |
| 1135 | + xcconfigs_map[config.name.to_s] = config |
| 1136 | + end |
| 1137 | + |
| 1138 | + pod_target_installation_results_map = {} |
| 1139 | + build_configs.each do |name, build_configs| |
| 1140 | + pod_target_installation_results_map[name.to_s] = prepare_pod_target_installation_results_mock( |
| 1141 | + name.to_s, build_configs |
| 1142 | + ) |
| 1143 | + end |
| 1144 | + |
| 1145 | + return InstallerMock.new( |
| 1146 | + PodsProjectMock.new, |
| 1147 | + [ |
| 1148 | + AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/") |
| 1149 | + ], |
| 1150 | + :pod_target_installation_results => pod_target_installation_results_map |
| 1151 | + ) |
| 1152 | +end |
| 1153 | + |
0 commit comments