| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. | 
|  | 2 | // | 
|  | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | // you may not use this file except in compliance with the License. | 
|  | 5 | // You may obtain a copy of the License at | 
|  | 6 | // | 
|  | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | // | 
|  | 9 | // Unless required by applicable law or agreed to in writing, software | 
|  | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | // See the License for the specific language governing permissions and | 
|  | 13 | // limitations under the License. | 
|  | 14 |  | 
|  | 15 | package python | 
|  | 16 |  | 
|  | 17 | import ( | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 18 | "fmt" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 19 | "os" | 
|  | 20 | "path/filepath" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 21 | "testing" | 
|  | 22 |  | 
|  | 23 | "android/soong/android" | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 24 | "android/soong/cc" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 25 | ) | 
|  | 26 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 27 | type pyModule struct { | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 28 | name          string | 
|  | 29 | actualVersion string | 
|  | 30 | pyRunfiles    []string | 
|  | 31 | srcsZip       string | 
|  | 32 | depsSrcsZips  []string | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 33 | } | 
|  | 34 |  | 
|  | 35 | var ( | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 36 | buildNamePrefix = "soong_python_test" | 
|  | 37 | // We allow maching almost anything before the actual variant so that the os/arch variant | 
|  | 38 | // is matched. | 
|  | 39 | moduleVariantErrTemplate = `%s: module %q variant "[a-zA-Z0-9_]*%s": ` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 40 | pkgPathErrTemplate       = moduleVariantErrTemplate + | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 41 | "pkg_path: %q must be a relative path contained in par file." | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 42 | badIdentifierErrTemplate = moduleVariantErrTemplate + | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 43 | "srcs: the path %q contains invalid subpath %q." | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 44 | dupRunfileErrTemplate = moduleVariantErrTemplate + | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 45 | "found two files to be placed at the same location within zip %q." + | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 46 | " First file: in module %s at path %q." + | 
|  | 47 | " Second file: in module %s at path %q." | 
|  | 48 | noSrcFileErr      = moduleVariantErrTemplate + "doesn't have any source files!" | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 49 | badSrcFileExtErr  = moduleVariantErrTemplate + "srcs: found non (.py|.proto) file: %q!" | 
|  | 50 | badDataFileExtErr = moduleVariantErrTemplate + "data: found (.py|.proto) file: %q!" | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 51 | bpFile            = "Android.bp" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 52 |  | 
|  | 53 | data = []struct { | 
|  | 54 | desc      string | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 55 | mockFiles android.MockFS | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 56 |  | 
|  | 57 | errors           []string | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 58 | expectedBinaries []pyModule | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 59 | }{ | 
|  | 60 | { | 
|  | 61 | desc: "module without any src files", | 
|  | 62 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 63 | filepath.Join("dir", bpFile): []byte( | 
|  | 64 | `python_library_host { | 
|  | 65 | name: "lib1", | 
|  | 66 | }`, | 
|  | 67 | ), | 
|  | 68 | }, | 
|  | 69 | errors: []string{ | 
|  | 70 | fmt.Sprintf(noSrcFileErr, | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 71 | "dir/Android.bp:1:1", "lib1", "PY3"), | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 72 | }, | 
|  | 73 | }, | 
|  | 74 | { | 
|  | 75 | desc: "module with bad src file ext", | 
|  | 76 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 77 | filepath.Join("dir", bpFile): []byte( | 
|  | 78 | `python_library_host { | 
|  | 79 | name: "lib1", | 
|  | 80 | srcs: [ | 
|  | 81 | "file1.exe", | 
|  | 82 | ], | 
|  | 83 | }`, | 
|  | 84 | ), | 
|  | 85 | "dir/file1.exe": nil, | 
|  | 86 | }, | 
|  | 87 | errors: []string{ | 
|  | 88 | fmt.Sprintf(badSrcFileExtErr, | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 89 | "dir/Android.bp:3:11", "lib1", "PY3", "dir/file1.exe"), | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 90 | }, | 
|  | 91 | }, | 
|  | 92 | { | 
|  | 93 | desc: "module with bad data file ext", | 
|  | 94 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 95 | filepath.Join("dir", bpFile): []byte( | 
|  | 96 | `python_library_host { | 
|  | 97 | name: "lib1", | 
|  | 98 | srcs: [ | 
|  | 99 | "file1.py", | 
|  | 100 | ], | 
|  | 101 | data: [ | 
|  | 102 | "file2.py", | 
|  | 103 | ], | 
|  | 104 | }`, | 
|  | 105 | ), | 
|  | 106 | "dir/file1.py": nil, | 
|  | 107 | "dir/file2.py": nil, | 
|  | 108 | }, | 
|  | 109 | errors: []string{ | 
|  | 110 | fmt.Sprintf(badDataFileExtErr, | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 111 | "dir/Android.bp:6:11", "lib1", "PY3", "dir/file2.py"), | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 112 | }, | 
|  | 113 | }, | 
|  | 114 | { | 
|  | 115 | desc: "module with bad pkg_path format", | 
|  | 116 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 117 | filepath.Join("dir", bpFile): []byte( | 
|  | 118 | `python_library_host { | 
|  | 119 | name: "lib1", | 
|  | 120 | pkg_path: "a/c/../../", | 
|  | 121 | srcs: [ | 
|  | 122 | "file1.py", | 
|  | 123 | ], | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | python_library_host { | 
|  | 127 | name: "lib2", | 
|  | 128 | pkg_path: "a/c/../../../", | 
|  | 129 | srcs: [ | 
|  | 130 | "file1.py", | 
|  | 131 | ], | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | python_library_host { | 
|  | 135 | name: "lib3", | 
|  | 136 | pkg_path: "/a/c/../../", | 
|  | 137 | srcs: [ | 
|  | 138 | "file1.py", | 
|  | 139 | ], | 
|  | 140 | }`, | 
|  | 141 | ), | 
|  | 142 | "dir/file1.py": nil, | 
|  | 143 | }, | 
|  | 144 | errors: []string{ | 
|  | 145 | fmt.Sprintf(pkgPathErrTemplate, | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 146 | "dir/Android.bp:11:15", "lib2", "PY3", "a/c/../../../"), | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 147 | fmt.Sprintf(pkgPathErrTemplate, | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 148 | "dir/Android.bp:19:15", "lib3", "PY3", "/a/c/../../"), | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 149 | }, | 
|  | 150 | }, | 
|  | 151 | { | 
|  | 152 | desc: "module with bad runfile src path format", | 
|  | 153 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 154 | filepath.Join("dir", bpFile): []byte( | 
|  | 155 | `python_library_host { | 
|  | 156 | name: "lib1", | 
|  | 157 | pkg_path: "a/b/c/", | 
|  | 158 | srcs: [ | 
|  | 159 | ".file1.py", | 
|  | 160 | "123/file1.py", | 
|  | 161 | "-e/f/file1.py", | 
|  | 162 | ], | 
|  | 163 | }`, | 
|  | 164 | ), | 
|  | 165 | "dir/.file1.py":     nil, | 
|  | 166 | "dir/123/file1.py":  nil, | 
|  | 167 | "dir/-e/f/file1.py": nil, | 
|  | 168 | }, | 
|  | 169 | errors: []string{ | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 170 | fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 171 | "lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"), | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 172 | fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 173 | "lib1", "PY3", "a/b/c/.file1.py", ".file1"), | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 174 | fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 175 | "lib1", "PY3", "a/b/c/123/file1.py", "123"), | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 176 | }, | 
|  | 177 | }, | 
|  | 178 | { | 
|  | 179 | desc: "module with duplicate runfile path", | 
|  | 180 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 181 | filepath.Join("dir", bpFile): []byte( | 
|  | 182 | `python_library_host { | 
|  | 183 | name: "lib1", | 
|  | 184 | pkg_path: "a/b/", | 
|  | 185 | srcs: [ | 
|  | 186 | "c/file1.py", | 
|  | 187 | ], | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | python_library_host { | 
|  | 191 | name: "lib2", | 
|  | 192 | pkg_path: "a/b/c/", | 
|  | 193 | srcs: [ | 
|  | 194 | "file1.py", | 
|  | 195 | ], | 
|  | 196 | libs: [ | 
|  | 197 | "lib1", | 
|  | 198 | ], | 
|  | 199 | } | 
| Paul Duffin | c60dd80 | 2021-03-17 23:01:06 +0000 | [diff] [blame] | 200 |  | 
|  | 201 | python_binary_host { | 
|  | 202 | name: "bin", | 
|  | 203 | pkg_path: "e/", | 
|  | 204 | srcs: [ | 
|  | 205 | "bin.py", | 
|  | 206 | ], | 
|  | 207 | libs: [ | 
|  | 208 | "lib2", | 
|  | 209 | ], | 
|  | 210 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 211 | `, | 
|  | 212 | ), | 
|  | 213 | "dir/c/file1.py": nil, | 
|  | 214 | "dir/file1.py":   nil, | 
| Paul Duffin | c60dd80 | 2021-03-17 23:01:06 +0000 | [diff] [blame] | 215 | "dir/bin.py":     nil, | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 216 | }, | 
|  | 217 | errors: []string{ | 
| Paul Duffin | c60dd80 | 2021-03-17 23:01:06 +0000 | [diff] [blame] | 218 | fmt.Sprintf(dupRunfileErrTemplate, "dir/Android.bp:20:6", | 
|  | 219 | "bin", "PY3", "a/b/c/file1.py", "bin", "dir/file1.py", | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 220 | "lib1", "dir/c/file1.py"), | 
|  | 221 | }, | 
|  | 222 | }, | 
|  | 223 | { | 
|  | 224 | desc: "module for testing dependencies", | 
|  | 225 | mockFiles: map[string][]byte{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 226 | filepath.Join("dir", bpFile): []byte( | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 227 | `python_defaults { | 
|  | 228 | name: "default_lib", | 
|  | 229 | srcs: [ | 
|  | 230 | "default.py", | 
|  | 231 | ], | 
|  | 232 | version: { | 
|  | 233 | py2: { | 
|  | 234 | enabled: true, | 
|  | 235 | srcs: [ | 
|  | 236 | "default_py2.py", | 
|  | 237 | ], | 
|  | 238 | }, | 
|  | 239 | py3: { | 
|  | 240 | enabled: false, | 
|  | 241 | srcs: [ | 
|  | 242 | "default_py3.py", | 
|  | 243 | ], | 
|  | 244 | }, | 
|  | 245 | }, | 
|  | 246 | } | 
|  | 247 |  | 
|  | 248 | python_library_host { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 249 | name: "lib5", | 
|  | 250 | pkg_path: "a/b/", | 
|  | 251 | srcs: [ | 
|  | 252 | "file1.py", | 
|  | 253 | ], | 
|  | 254 | version: { | 
|  | 255 | py2: { | 
|  | 256 | enabled: true, | 
|  | 257 | }, | 
|  | 258 | py3: { | 
|  | 259 | enabled: true, | 
|  | 260 | }, | 
|  | 261 | }, | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 | python_library_host { | 
|  | 265 | name: "lib6", | 
|  | 266 | pkg_path: "c/d/", | 
|  | 267 | srcs: [ | 
|  | 268 | "file2.py", | 
|  | 269 | ], | 
|  | 270 | libs: [ | 
|  | 271 | "lib5", | 
|  | 272 | ], | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | python_binary_host { | 
|  | 276 | name: "bin", | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 277 | defaults: ["default_lib"], | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 278 | pkg_path: "e/", | 
|  | 279 | srcs: [ | 
|  | 280 | "bin.py", | 
|  | 281 | ], | 
|  | 282 | libs: [ | 
|  | 283 | "lib5", | 
|  | 284 | ], | 
|  | 285 | version: { | 
|  | 286 | py3: { | 
|  | 287 | enabled: true, | 
|  | 288 | srcs: [ | 
|  | 289 | "file4.py", | 
|  | 290 | ], | 
|  | 291 | libs: [ | 
|  | 292 | "lib6", | 
|  | 293 | ], | 
|  | 294 | }, | 
|  | 295 | }, | 
|  | 296 | }`, | 
|  | 297 | ), | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 298 | filepath.Join("dir", "default.py"):     nil, | 
|  | 299 | filepath.Join("dir", "default_py2.py"): nil, | 
|  | 300 | filepath.Join("dir", "default_py3.py"): nil, | 
|  | 301 | filepath.Join("dir", "file1.py"):       nil, | 
|  | 302 | filepath.Join("dir", "file2.py"):       nil, | 
|  | 303 | filepath.Join("dir", "bin.py"):         nil, | 
|  | 304 | filepath.Join("dir", "file4.py"):       nil, | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 305 | }, | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 306 | expectedBinaries: []pyModule{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 307 | { | 
|  | 308 | name:          "bin", | 
|  | 309 | actualVersion: "PY3", | 
|  | 310 | pyRunfiles: []string{ | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 311 | "e/default.py", | 
|  | 312 | "e/bin.py", | 
|  | 313 | "e/default_py3.py", | 
|  | 314 | "e/file4.py", | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 315 | }, | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 316 | srcsZip: "out/soong/.intermediates/dir/bin/PY3/bin.py.srcszip", | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 317 | }, | 
|  | 318 | }, | 
|  | 319 | }, | 
|  | 320 | } | 
|  | 321 | ) | 
|  | 322 |  | 
|  | 323 | func TestPythonModule(t *testing.T) { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 324 | for _, d := range data { | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 325 | if d.desc != "module with duplicate runfile path" { | 
|  | 326 | continue | 
|  | 327 | } | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 328 | d.mockFiles[filepath.Join("common", bpFile)] = []byte(` | 
|  | 329 | python_library { | 
|  | 330 | name: "py3-stdlib", | 
|  | 331 | host_supported: true, | 
|  | 332 | } | 
|  | 333 | cc_binary { | 
|  | 334 | name: "py3-launcher", | 
|  | 335 | host_supported: true, | 
|  | 336 | } | 
|  | 337 | `) | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 338 |  | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 339 | t.Run(d.desc, func(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 340 | result := android.GroupFixturePreparers( | 
|  | 341 | android.PrepareForTestWithDefaults, | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 342 | android.PrepareForTestWithArchMutator, | 
|  | 343 | android.PrepareForTestWithAllowMissingDependencies, | 
|  | 344 | cc.PrepareForTestWithCcDefaultModules, | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 345 | PrepareForTestWithPythonBuildComponents, | 
|  | 346 | d.mockFiles.AddToFixture(), | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 347 | ).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(d.errors)). | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 348 | RunTest(t) | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 349 |  | 
|  | 350 | if len(result.Errs) > 0 { | 
|  | 351 | return | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 352 | } | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 353 |  | 
|  | 354 | for _, e := range d.expectedBinaries { | 
|  | 355 | t.Run(e.name, func(t *testing.T) { | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 356 | expectModule(t, result.TestContext, e.name, e.actualVersion, e.srcsZip, e.pyRunfiles) | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 357 | }) | 
|  | 358 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 359 | }) | 
|  | 360 | } | 
|  | 361 | } | 
|  | 362 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 363 | func expectModule(t *testing.T, ctx *android.TestContext, name, variant, expectedSrcsZip string, expectedPyRunfiles []string) { | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 364 | module := ctx.ModuleForTests(name, variant) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 365 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 366 | base, baseOk := module.Module().(*PythonLibraryModule) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 367 | if !baseOk { | 
|  | 368 | t.Fatalf("%s is not Python module!", name) | 
|  | 369 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 370 |  | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 371 | actualPyRunfiles := []string{} | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 372 | for _, path := range base.srcsPathMappings { | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 373 | actualPyRunfiles = append(actualPyRunfiles, path.dest) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 374 | } | 
|  | 375 |  | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 376 | android.AssertDeepEquals(t, "pyRunfiles", expectedPyRunfiles, actualPyRunfiles) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 377 |  | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 378 | android.AssertPathRelativeToTopEquals(t, "srcsZip", expectedSrcsZip, base.srcsZip) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 379 | } | 
|  | 380 |  | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 381 | func TestMain(m *testing.M) { | 
| Paul Duffin | 803876aa | 2021-03-17 22:38:23 +0000 | [diff] [blame] | 382 | os.Exit(m.Run()) | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 383 | } |