Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2022 The Gleam contributors 3 4use super::NativeFileCopier; 5use crate::{ 6 build::{native_file_copier::CopiedNativeFiles, package_compiler::CheckModuleConflicts}, 7 io::{FileSystemWriter, memory::InMemoryFileSystem}, 8}; 9use std::{ 10 collections::HashMap, 11 sync::OnceLock, 12 time::{Duration, SystemTime, UNIX_EPOCH}, 13}; 14 15use camino::{Utf8Path, Utf8PathBuf}; 16 17fn root() -> &'static Utf8PathBuf { 18 static ROOT: OnceLock<Utf8PathBuf> = OnceLock::new(); 19 ROOT.get_or_init(|| Utf8PathBuf::from("/").to_owned()) 20} 21 22fn root_out() -> &'static Utf8PathBuf { 23 static OUT: OnceLock<Utf8PathBuf> = OnceLock::new(); 24 OUT.get_or_init(|| Utf8PathBuf::from("/out")) 25} 26 27#[test] 28fn javascript_files_are_copied_from_src() { 29 let fs = InMemoryFileSystem::new(); 30 fs.write(&Utf8Path::new("/src/wibble.js"), "1").unwrap(); 31 32 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 33 let copied = copier.run().unwrap(); 34 35 assert!(!copied.any_elixir); 36 assert!(copied.to_compile.is_empty()); 37 assert_eq!( 38 HashMap::from([ 39 (Utf8PathBuf::from("/src/wibble.js"), "1".into()), 40 (Utf8PathBuf::from("/out/wibble.js"), "1".into()) 41 ]), 42 fs.into_contents(), 43 ); 44} 45 46#[test] 47fn javascript_files_are_copied_from_test() { 48 let fs = InMemoryFileSystem::new(); 49 fs.write(&Utf8Path::new("/test/wibble.js"), "1").unwrap(); 50 51 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 52 let copied = copier.run().unwrap(); 53 54 assert!(!copied.any_elixir); 55 assert!(copied.to_compile.is_empty()); 56 assert_eq!( 57 HashMap::from([ 58 (Utf8PathBuf::from("/test/wibble.js"), "1".into()), 59 (Utf8PathBuf::from("/out/wibble.js"), "1".into()) 60 ]), 61 fs.into_contents(), 62 ); 63} 64 65#[test] 66fn javascript_files_are_copied_from_dev() { 67 let fs = InMemoryFileSystem::new(); 68 fs.write(&Utf8Path::new("/dev/wibble.js"), "1").unwrap(); 69 70 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 71 let copied = copier.run().unwrap(); 72 73 assert!(!copied.any_elixir); 74 assert!(copied.to_compile.is_empty()); 75 assert_eq!( 76 HashMap::from([ 77 (Utf8PathBuf::from("/dev/wibble.js"), "1".into()), 78 (Utf8PathBuf::from("/out/wibble.js"), "1".into()) 79 ]), 80 fs.into_contents(), 81 ); 82} 83 84#[test] 85fn mjavascript_files_are_copied_from_src() { 86 let fs = InMemoryFileSystem::new(); 87 fs.write(&Utf8Path::new("/src/wibble.mjs"), "1").unwrap(); 88 89 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 90 let copied = copier.run().unwrap(); 91 92 assert!(!copied.any_elixir); 93 assert!(copied.to_compile.is_empty()); 94 assert_eq!( 95 HashMap::from([ 96 (Utf8PathBuf::from("/src/wibble.mjs"), "1".into()), 97 (Utf8PathBuf::from("/out/wibble.mjs"), "1".into()) 98 ]), 99 fs.into_contents(), 100 ); 101} 102 103#[test] 104fn mjavascript_files_are_copied_from_test() { 105 let fs = InMemoryFileSystem::new(); 106 fs.write(&Utf8Path::new("/test/wibble.mjs"), "1").unwrap(); 107 108 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 109 let copied = copier.run().unwrap(); 110 111 assert!(!copied.any_elixir); 112 assert!(copied.to_compile.is_empty()); 113 assert_eq!( 114 HashMap::from([ 115 (Utf8PathBuf::from("/test/wibble.mjs"), "1".into()), 116 (Utf8PathBuf::from("/out/wibble.mjs"), "1".into()) 117 ]), 118 fs.into_contents(), 119 ); 120} 121 122#[test] 123fn mjavascript_files_are_copied_from_dev() { 124 let fs = InMemoryFileSystem::new(); 125 fs.write(&Utf8Path::new("/dev/wibble.mjs"), "1").unwrap(); 126 127 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 128 let copied = copier.run().unwrap(); 129 130 assert!(!copied.any_elixir); 131 assert!(copied.to_compile.is_empty()); 132 assert_eq!( 133 HashMap::from([ 134 (Utf8PathBuf::from("/dev/wibble.mjs"), "1".into()), 135 (Utf8PathBuf::from("/out/wibble.mjs"), "1".into()) 136 ]), 137 fs.into_contents(), 138 ); 139} 140 141#[test] 142fn cjavascript_files_are_copied_from_src() { 143 let fs = InMemoryFileSystem::new(); 144 fs.write(&Utf8Path::new("/src/wibble.cjs"), "1").unwrap(); 145 146 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 147 let copied = copier.run().unwrap(); 148 149 assert!(!copied.any_elixir); 150 assert!(copied.to_compile.is_empty()); 151 assert_eq!( 152 HashMap::from([ 153 (Utf8PathBuf::from("/src/wibble.cjs"), "1".into()), 154 (Utf8PathBuf::from("/out/wibble.cjs"), "1".into()) 155 ]), 156 fs.into_contents(), 157 ); 158} 159 160#[test] 161fn cjavascript_files_are_copied_from_test() { 162 let fs = InMemoryFileSystem::new(); 163 fs.write(&Utf8Path::new("/test/wibble.cjs"), "1").unwrap(); 164 165 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 166 let copied = copier.run().unwrap(); 167 168 assert!(!copied.any_elixir); 169 assert!(copied.to_compile.is_empty()); 170 assert_eq!( 171 HashMap::from([ 172 (Utf8PathBuf::from("/test/wibble.cjs"), "1".into()), 173 (Utf8PathBuf::from("/out/wibble.cjs"), "1".into()) 174 ]), 175 fs.into_contents(), 176 ); 177} 178 179#[test] 180fn cjavascript_files_are_copied_from_dev() { 181 let fs = InMemoryFileSystem::new(); 182 fs.write(&Utf8Path::new("/dev/wibble.cjs"), "1").unwrap(); 183 184 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 185 let copied = copier.run().unwrap(); 186 187 assert!(!copied.any_elixir); 188 assert!(copied.to_compile.is_empty()); 189 assert_eq!( 190 HashMap::from([ 191 (Utf8PathBuf::from("/dev/wibble.cjs"), "1".into()), 192 (Utf8PathBuf::from("/out/wibble.cjs"), "1".into()) 193 ]), 194 fs.into_contents(), 195 ); 196} 197 198#[test] 199fn javascriptx_files_are_copied_from_src() { 200 let fs = InMemoryFileSystem::new(); 201 fs.write(&Utf8Path::new("/src/wibble.jsx"), "1").unwrap(); 202 203 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 204 let copied = copier.run().unwrap(); 205 206 assert!(!copied.any_elixir); 207 assert!(copied.to_compile.is_empty()); 208 assert_eq!( 209 HashMap::from([ 210 (Utf8PathBuf::from("/src/wibble.jsx"), "1".into()), 211 (Utf8PathBuf::from("/out/wibble.jsx"), "1".into()) 212 ]), 213 fs.into_contents(), 214 ); 215} 216 217#[test] 218fn javascriptx_files_are_copied_from_test() { 219 let fs = InMemoryFileSystem::new(); 220 fs.write(&Utf8Path::new("/test/wibble.jsx"), "1").unwrap(); 221 222 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 223 let copied = copier.run().unwrap(); 224 225 assert!(!copied.any_elixir); 226 assert!(copied.to_compile.is_empty()); 227 assert_eq!( 228 HashMap::from([ 229 (Utf8PathBuf::from("/test/wibble.jsx"), "1".into()), 230 (Utf8PathBuf::from("/out/wibble.jsx"), "1".into()) 231 ]), 232 fs.into_contents(), 233 ); 234} 235 236#[test] 237fn javascriptx_files_are_copied_from_dev() { 238 let fs = InMemoryFileSystem::new(); 239 fs.write(&Utf8Path::new("/dev/wibble.jsx"), "1").unwrap(); 240 241 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 242 let copied = copier.run().unwrap(); 243 244 assert!(!copied.any_elixir); 245 assert!(copied.to_compile.is_empty()); 246 assert_eq!( 247 HashMap::from([ 248 (Utf8PathBuf::from("/dev/wibble.jsx"), "1".into()), 249 (Utf8PathBuf::from("/out/wibble.jsx"), "1".into()) 250 ]), 251 fs.into_contents(), 252 ); 253} 254 255#[test] 256fn typescript_files_are_copied_from_src() { 257 let fs = InMemoryFileSystem::new(); 258 fs.write(&Utf8Path::new("/src/wibble.ts"), "1").unwrap(); 259 260 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 261 let copied = copier.run().unwrap(); 262 263 assert!(!copied.any_elixir); 264 assert!(copied.to_compile.is_empty()); 265 assert_eq!( 266 HashMap::from([ 267 (Utf8PathBuf::from("/src/wibble.ts"), "1".into()), 268 (Utf8PathBuf::from("/out/wibble.ts"), "1".into()) 269 ]), 270 fs.into_contents(), 271 ); 272} 273 274#[test] 275fn typescript_files_are_copied_from_test() { 276 let fs = InMemoryFileSystem::new(); 277 fs.write(&Utf8Path::new("/test/wibble.ts"), "1").unwrap(); 278 279 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 280 let copied = copier.run().unwrap(); 281 282 assert!(!copied.any_elixir); 283 assert!(copied.to_compile.is_empty()); 284 assert_eq!( 285 HashMap::from([ 286 (Utf8PathBuf::from("/test/wibble.ts"), "1".into()), 287 (Utf8PathBuf::from("/out/wibble.ts"), "1".into()) 288 ]), 289 fs.into_contents(), 290 ); 291} 292 293#[test] 294fn typescript_files_are_copied_from_dev() { 295 let fs = InMemoryFileSystem::new(); 296 fs.write(&Utf8Path::new("/dev/wibble.ts"), "1").unwrap(); 297 298 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 299 let copied = copier.run().unwrap(); 300 301 assert!(!copied.any_elixir); 302 assert!(copied.to_compile.is_empty()); 303 assert_eq!( 304 HashMap::from([ 305 (Utf8PathBuf::from("/dev/wibble.ts"), "1".into()), 306 (Utf8PathBuf::from("/out/wibble.ts"), "1".into()) 307 ]), 308 fs.into_contents(), 309 ); 310} 311 312#[test] 313fn mtypescript_files_are_copied_from_src() { 314 let fs = InMemoryFileSystem::new(); 315 fs.write(&Utf8Path::new("/src/wibble.mts"), "1").unwrap(); 316 317 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 318 let copied = copier.run().unwrap(); 319 320 assert!(!copied.any_elixir); 321 assert!(copied.to_compile.is_empty()); 322 assert_eq!( 323 HashMap::from([ 324 (Utf8PathBuf::from("/src/wibble.mts"), "1".into()), 325 (Utf8PathBuf::from("/out/wibble.mts"), "1".into()) 326 ]), 327 fs.into_contents(), 328 ); 329} 330 331#[test] 332fn mtypescript_files_are_copied_from_test() { 333 let fs = InMemoryFileSystem::new(); 334 fs.write(&Utf8Path::new("/test/wibble.mts"), "1").unwrap(); 335 336 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 337 let copied = copier.run().unwrap(); 338 339 assert!(!copied.any_elixir); 340 assert!(copied.to_compile.is_empty()); 341 assert_eq!( 342 HashMap::from([ 343 (Utf8PathBuf::from("/test/wibble.mts"), "1".into()), 344 (Utf8PathBuf::from("/out/wibble.mts"), "1".into()) 345 ]), 346 fs.into_contents(), 347 ); 348} 349 350#[test] 351fn mtypescript_files_are_copied_from_dev() { 352 let fs = InMemoryFileSystem::new(); 353 fs.write(&Utf8Path::new("/dev/wibble.mts"), "1").unwrap(); 354 355 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 356 let copied = copier.run().unwrap(); 357 358 assert!(!copied.any_elixir); 359 assert!(copied.to_compile.is_empty()); 360 assert_eq!( 361 HashMap::from([ 362 (Utf8PathBuf::from("/dev/wibble.mts"), "1".into()), 363 (Utf8PathBuf::from("/out/wibble.mts"), "1".into()) 364 ]), 365 fs.into_contents(), 366 ); 367} 368 369#[test] 370fn ctypescript_files_are_copied_from_src() { 371 let fs = InMemoryFileSystem::new(); 372 fs.write(&Utf8Path::new("/src/wibble.cts"), "1").unwrap(); 373 374 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 375 let copied = copier.run().unwrap(); 376 377 assert!(!copied.any_elixir); 378 assert!(copied.to_compile.is_empty()); 379 assert_eq!( 380 HashMap::from([ 381 (Utf8PathBuf::from("/src/wibble.cts"), "1".into()), 382 (Utf8PathBuf::from("/out/wibble.cts"), "1".into()) 383 ]), 384 fs.into_contents(), 385 ); 386} 387 388#[test] 389fn ctypescript_files_are_copied_from_test() { 390 let fs = InMemoryFileSystem::new(); 391 fs.write(&Utf8Path::new("/test/wibble.cts"), "1").unwrap(); 392 393 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 394 let copied = copier.run().unwrap(); 395 396 assert!(!copied.any_elixir); 397 assert!(copied.to_compile.is_empty()); 398 assert_eq!( 399 HashMap::from([ 400 (Utf8PathBuf::from("/test/wibble.cts"), "1".into()), 401 (Utf8PathBuf::from("/out/wibble.cts"), "1".into()) 402 ]), 403 fs.into_contents(), 404 ); 405} 406 407#[test] 408fn ctypescript_files_are_copied_from_dev() { 409 let fs = InMemoryFileSystem::new(); 410 fs.write(&Utf8Path::new("/dev/wibble.cts"), "1").unwrap(); 411 412 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 413 let copied = copier.run().unwrap(); 414 415 assert!(!copied.any_elixir); 416 assert!(copied.to_compile.is_empty()); 417 assert_eq!( 418 HashMap::from([ 419 (Utf8PathBuf::from("/dev/wibble.cts"), "1".into()), 420 (Utf8PathBuf::from("/out/wibble.cts"), "1".into()) 421 ]), 422 fs.into_contents(), 423 ); 424} 425 426#[test] 427fn typescriptx_files_are_copied_from_src() { 428 let fs = InMemoryFileSystem::new(); 429 fs.write(&Utf8Path::new("/src/wibble.tsx"), "1").unwrap(); 430 431 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 432 let copied = copier.run().unwrap(); 433 434 assert!(!copied.any_elixir); 435 assert!(copied.to_compile.is_empty()); 436 assert_eq!( 437 HashMap::from([ 438 (Utf8PathBuf::from("/src/wibble.tsx"), "1".into()), 439 (Utf8PathBuf::from("/out/wibble.tsx"), "1".into()) 440 ]), 441 fs.into_contents(), 442 ); 443} 444 445#[test] 446fn typescriptx_files_are_copied_from_test() { 447 let fs = InMemoryFileSystem::new(); 448 fs.write(&Utf8Path::new("/test/wibble.tsx"), "1").unwrap(); 449 450 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 451 let copied = copier.run().unwrap(); 452 453 assert!(!copied.any_elixir); 454 assert!(copied.to_compile.is_empty()); 455 assert_eq!( 456 HashMap::from([ 457 (Utf8PathBuf::from("/test/wibble.tsx"), "1".into()), 458 (Utf8PathBuf::from("/out/wibble.tsx"), "1".into()) 459 ]), 460 fs.into_contents(), 461 ); 462} 463 464#[test] 465fn typescriptx_files_are_copied_from_dev() { 466 let fs = InMemoryFileSystem::new(); 467 fs.write(&Utf8Path::new("/dev/wibble.tsx"), "1").unwrap(); 468 469 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 470 let copied = copier.run().unwrap(); 471 472 assert!(!copied.any_elixir); 473 assert!(copied.to_compile.is_empty()); 474 assert_eq!( 475 HashMap::from([ 476 (Utf8PathBuf::from("/dev/wibble.tsx"), "1".into()), 477 (Utf8PathBuf::from("/out/wibble.tsx"), "1".into()) 478 ]), 479 fs.into_contents(), 480 ); 481} 482 483#[test] 484fn all_javascript_files_are_copied_from_src_subfolders() { 485 let fs = InMemoryFileSystem::new(); 486 fs.write(&Utf8Path::new("/src/abc/def/wibble.mjs"), "1") 487 .unwrap(); 488 fs.write(&Utf8Path::new("/src/abc/ghi/wibble.js"), "2") 489 .unwrap(); 490 fs.write(&Utf8Path::new("/src/abc/jkl/wibble.cjs"), "3") 491 .unwrap(); 492 fs.write(&Utf8Path::new("/src/abc/jkl/wibble.jsx"), "4") 493 .unwrap(); 494 fs.write(&Utf8Path::new("/src/def/wobble.ts"), "5").unwrap(); 495 fs.write(&Utf8Path::new("/src/def/wobble.mts"), "6") 496 .unwrap(); 497 fs.write(&Utf8Path::new("/src/def/wobble.cts"), "7") 498 .unwrap(); 499 fs.write(&Utf8Path::new("/src/def/wobble.tsx"), "8") 500 .unwrap(); 501 502 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 503 let copied = copier.run().unwrap(); 504 505 assert!(!copied.any_elixir); 506 assert!(copied.to_compile.is_empty()); 507 assert_eq!( 508 HashMap::from([ 509 (Utf8PathBuf::from("/src/abc/def/wibble.mjs"), "1".into()), 510 (Utf8PathBuf::from("/out/abc/def/wibble.mjs"), "1".into()), 511 (Utf8PathBuf::from("/src/abc/ghi/wibble.js"), "2".into()), 512 (Utf8PathBuf::from("/out/abc/ghi/wibble.js"), "2".into()), 513 (Utf8PathBuf::from("/src/abc/jkl/wibble.cjs"), "3".into()), 514 (Utf8PathBuf::from("/out/abc/jkl/wibble.cjs"), "3".into()), 515 (Utf8PathBuf::from("/src/abc/jkl/wibble.jsx"), "4".into()), 516 (Utf8PathBuf::from("/out/abc/jkl/wibble.jsx"), "4".into()), 517 (Utf8PathBuf::from("/src/def/wobble.ts"), "5".into()), 518 (Utf8PathBuf::from("/out/def/wobble.ts"), "5".into()), 519 (Utf8PathBuf::from("/src/def/wobble.mts"), "6".into()), 520 (Utf8PathBuf::from("/out/def/wobble.mts"), "6".into()), 521 (Utf8PathBuf::from("/src/def/wobble.cts"), "7".into()), 522 (Utf8PathBuf::from("/out/def/wobble.cts"), "7".into()), 523 (Utf8PathBuf::from("/src/def/wobble.tsx"), "8".into()), 524 (Utf8PathBuf::from("/out/def/wobble.tsx"), "8".into()), 525 ]), 526 fs.into_contents(), 527 ); 528} 529 530#[test] 531fn all_javascript_files_are_copied_from_test_subfolders() { 532 let fs = InMemoryFileSystem::new(); 533 fs.write(&Utf8Path::new("/test/abc/def/wibble.mjs"), "1") 534 .unwrap(); 535 fs.write(&Utf8Path::new("/test/abc/ghi/wibble.js"), "2") 536 .unwrap(); 537 fs.write(&Utf8Path::new("/test/abc/jkl/wibble.cjs"), "3") 538 .unwrap(); 539 fs.write(&Utf8Path::new("/test/abc/jkl/wibble.jsx"), "4") 540 .unwrap(); 541 fs.write(&Utf8Path::new("/test/def/wobble.ts"), "5") 542 .unwrap(); 543 fs.write(&Utf8Path::new("/test/def/wobble.mts"), "6") 544 .unwrap(); 545 fs.write(&Utf8Path::new("/test/def/wobble.cts"), "7") 546 .unwrap(); 547 fs.write(&Utf8Path::new("/test/def/wobble.tsx"), "8") 548 .unwrap(); 549 550 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 551 let copied = copier.run().unwrap(); 552 553 assert!(!copied.any_elixir); 554 assert!(copied.to_compile.is_empty()); 555 assert_eq!( 556 HashMap::from([ 557 (Utf8PathBuf::from("/test/abc/def/wibble.mjs"), "1".into()), 558 (Utf8PathBuf::from("/out/abc/def/wibble.mjs"), "1".into()), 559 (Utf8PathBuf::from("/test/abc/ghi/wibble.js"), "2".into()), 560 (Utf8PathBuf::from("/out/abc/ghi/wibble.js"), "2".into()), 561 (Utf8PathBuf::from("/test/abc/jkl/wibble.cjs"), "3".into()), 562 (Utf8PathBuf::from("/out/abc/jkl/wibble.cjs"), "3".into()), 563 (Utf8PathBuf::from("/test/abc/jkl/wibble.jsx"), "4".into()), 564 (Utf8PathBuf::from("/out/abc/jkl/wibble.jsx"), "4".into()), 565 (Utf8PathBuf::from("/test/def/wobble.ts"), "5".into()), 566 (Utf8PathBuf::from("/out/def/wobble.ts"), "5".into()), 567 (Utf8PathBuf::from("/test/def/wobble.mts"), "6".into()), 568 (Utf8PathBuf::from("/out/def/wobble.mts"), "6".into()), 569 (Utf8PathBuf::from("/test/def/wobble.cts"), "7".into()), 570 (Utf8PathBuf::from("/out/def/wobble.cts"), "7".into()), 571 (Utf8PathBuf::from("/test/def/wobble.tsx"), "8".into()), 572 (Utf8PathBuf::from("/out/def/wobble.tsx"), "8".into()), 573 ]), 574 fs.into_contents(), 575 ); 576} 577 578#[test] 579fn all_javascript_files_are_copied_from_dev_subfolders() { 580 let fs = InMemoryFileSystem::new(); 581 fs.write(&Utf8Path::new("/dev/abc/def/wibble.mjs"), "1") 582 .unwrap(); 583 fs.write(&Utf8Path::new("/dev/abc/ghi/wibble.js"), "2") 584 .unwrap(); 585 fs.write(&Utf8Path::new("/dev/abc/jkl/wibble.cjs"), "3") 586 .unwrap(); 587 fs.write(&Utf8Path::new("/dev/def/wobble.ts"), "4").unwrap(); 588 589 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 590 let copied = copier.run().unwrap(); 591 592 assert!(!copied.any_elixir); 593 assert!(copied.to_compile.is_empty()); 594 assert_eq!( 595 HashMap::from([ 596 (Utf8PathBuf::from("/dev/abc/def/wibble.mjs"), "1".into()), 597 (Utf8PathBuf::from("/out/abc/def/wibble.mjs"), "1".into()), 598 (Utf8PathBuf::from("/dev/abc/ghi/wibble.js"), "2".into()), 599 (Utf8PathBuf::from("/out/abc/ghi/wibble.js"), "2".into()), 600 (Utf8PathBuf::from("/dev/abc/jkl/wibble.cjs"), "3".into()), 601 (Utf8PathBuf::from("/out/abc/jkl/wibble.cjs"), "3".into()), 602 (Utf8PathBuf::from("/dev/def/wobble.ts"), "4".into()), 603 (Utf8PathBuf::from("/out/def/wobble.ts"), "4".into()) 604 ]), 605 fs.into_contents(), 606 ); 607} 608 609#[test] 610fn erlang_header_files_are_copied_from_src() { 611 let fs = InMemoryFileSystem::new(); 612 fs.write(&Utf8Path::new("/src/wibble.hrl"), "1").unwrap(); 613 614 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 615 let copied = copier.run().unwrap(); 616 617 assert!(!copied.any_elixir); 618 assert!(copied.to_compile.is_empty()); 619 assert_eq!( 620 HashMap::from([ 621 (Utf8PathBuf::from("/src/wibble.hrl"), "1".into()), 622 (Utf8PathBuf::from("/out/wibble.hrl"), "1".into()) 623 ]), 624 fs.into_contents(), 625 ); 626} 627 628#[test] 629fn erlang_header_files_are_copied_from_test() { 630 let fs = InMemoryFileSystem::new(); 631 fs.write(&Utf8Path::new("/test/wibble.hrl"), "1").unwrap(); 632 633 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 634 let copied = copier.run().unwrap(); 635 636 assert!(!copied.any_elixir); 637 assert!(copied.to_compile.is_empty()); 638 assert_eq!( 639 HashMap::from([ 640 (Utf8PathBuf::from("/test/wibble.hrl"), "1".into()), 641 (Utf8PathBuf::from("/out/wibble.hrl"), "1".into()) 642 ]), 643 fs.into_contents(), 644 ); 645} 646 647#[test] 648fn erlang_header_files_are_copied_from_dev() { 649 let fs = InMemoryFileSystem::new(); 650 fs.write(&Utf8Path::new("/dev/wibble.hrl"), "1").unwrap(); 651 652 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 653 let copied = copier.run().unwrap(); 654 655 assert!(!copied.any_elixir); 656 assert!(copied.to_compile.is_empty()); 657 assert_eq!( 658 HashMap::from([ 659 (Utf8PathBuf::from("/dev/wibble.hrl"), "1".into()), 660 (Utf8PathBuf::from("/out/wibble.hrl"), "1".into()) 661 ]), 662 fs.into_contents(), 663 ); 664} 665 666#[test] 667fn erlang_files_are_copied_from_src() { 668 let fs = InMemoryFileSystem::new(); 669 fs.write(&Utf8Path::new("/src/wibble.erl"), "1").unwrap(); 670 671 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 672 let copied = copier.run().unwrap(); 673 674 assert!(!copied.any_elixir); 675 assert_eq!(copied.to_compile, vec![Utf8PathBuf::from("wibble.erl")]); 676 assert_eq!( 677 HashMap::from([ 678 (Utf8PathBuf::from("/src/wibble.erl"), "1".into()), 679 (Utf8PathBuf::from("/out/wibble.erl"), "1".into()) 680 ]), 681 fs.into_contents(), 682 ); 683} 684 685#[test] 686fn erlang_files_are_copied_from_test() { 687 let fs = InMemoryFileSystem::new(); 688 fs.write(&Utf8Path::new("/test/wibble.erl"), "1").unwrap(); 689 690 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 691 let copied = copier.run().unwrap(); 692 693 assert!(!copied.any_elixir); 694 assert_eq!(copied.to_compile, vec![Utf8PathBuf::from("wibble.erl")]); 695 assert_eq!( 696 HashMap::from([ 697 (Utf8PathBuf::from("/test/wibble.erl"), "1".into()), 698 (Utf8PathBuf::from("/out/wibble.erl"), "1".into()) 699 ]), 700 fs.into_contents(), 701 ); 702} 703 704#[test] 705fn erlang_files_are_copied_from_dev() { 706 let fs = InMemoryFileSystem::new(); 707 fs.write(&Utf8Path::new("/dev/wibble.erl"), "1").unwrap(); 708 709 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 710 let copied = copier.run().unwrap(); 711 712 assert!(!copied.any_elixir); 713 assert_eq!(copied.to_compile, vec![Utf8PathBuf::from("wibble.erl")]); 714 assert_eq!( 715 HashMap::from([ 716 (Utf8PathBuf::from("/dev/wibble.erl"), "1".into()), 717 (Utf8PathBuf::from("/out/wibble.erl"), "1".into()) 718 ]), 719 fs.into_contents(), 720 ); 721} 722 723#[test] 724fn elixir_files_are_copied_from_src() { 725 let fs = InMemoryFileSystem::new(); 726 fs.write(&Utf8Path::new("/src/wibble.ex"), "1").unwrap(); 727 728 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 729 let copied = copier.run().unwrap(); 730 731 assert!(copied.any_elixir); 732 assert_eq!(copied.to_compile, vec![Utf8PathBuf::from("wibble.ex")]); 733 assert_eq!( 734 HashMap::from([ 735 (Utf8PathBuf::from("/src/wibble.ex"), "1".into()), 736 (Utf8PathBuf::from("/out/wibble.ex"), "1".into()) 737 ]), 738 fs.into_contents(), 739 ); 740} 741 742#[test] 743fn elixir_files_are_copied_from_test() { 744 let fs = InMemoryFileSystem::new(); 745 fs.write(&Utf8Path::new("/test/wibble.ex"), "1").unwrap(); 746 747 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 748 let copied = copier.run().unwrap(); 749 750 assert!(copied.any_elixir); 751 assert_eq!(copied.to_compile, vec![Utf8PathBuf::from("wibble.ex")]); 752 assert_eq!( 753 HashMap::from([ 754 (Utf8PathBuf::from("/test/wibble.ex"), "1".into()), 755 (Utf8PathBuf::from("/out/wibble.ex"), "1".into()) 756 ]), 757 fs.into_contents(), 758 ); 759} 760 761#[test] 762fn elixir_files_are_copied_from_dev() { 763 let fs = InMemoryFileSystem::new(); 764 fs.write(&Utf8Path::new("/dev/wibble.ex"), "1").unwrap(); 765 766 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 767 let copied = copier.run().unwrap(); 768 769 assert!(copied.any_elixir); 770 assert_eq!(copied.to_compile, vec![Utf8PathBuf::from("wibble.ex")]); 771 assert_eq!( 772 HashMap::from([ 773 (Utf8PathBuf::from("/dev/wibble.ex"), "1".into()), 774 (Utf8PathBuf::from("/out/wibble.ex"), "1".into()) 775 ]), 776 fs.into_contents(), 777 ); 778} 779 780#[test] 781fn all_erlang_files_are_copied_from_src_subfolders() { 782 let fs = InMemoryFileSystem::new(); 783 fs.write(&Utf8Path::new("/src/abc/def/wibble.erl"), "1") 784 .unwrap(); 785 fs.write(&Utf8Path::new("/src/abc/ghi/wibble_header.hrl"), "2") 786 .unwrap(); 787 fs.write(&Utf8Path::new("/src/def/wobble.ex"), "3").unwrap(); 788 789 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 790 let copied = copier.run().unwrap(); 791 792 assert!(copied.any_elixir); 793 assert_eq!( 794 copied.to_compile, 795 vec![ 796 Utf8PathBuf::from("abc/def/wibble.erl"), 797 Utf8PathBuf::from("def/wobble.ex") 798 ] 799 ); 800 assert_eq!( 801 HashMap::from([ 802 (Utf8PathBuf::from("/src/abc/def/wibble.erl"), "1".into()), 803 (Utf8PathBuf::from("/out/abc/def/wibble.erl"), "1".into()), 804 ( 805 Utf8PathBuf::from("/src/abc/ghi/wibble_header.hrl"), 806 "2".into() 807 ), 808 ( 809 Utf8PathBuf::from("/out/abc/ghi/wibble_header.hrl"), 810 "2".into() 811 ), 812 (Utf8PathBuf::from("/src/def/wobble.ex"), "3".into()), 813 (Utf8PathBuf::from("/out/def/wobble.ex"), "3".into()) 814 ]), 815 fs.into_contents(), 816 ); 817} 818 819#[test] 820fn all_erlang_files_are_copied_from_test_subfolders() { 821 let fs = InMemoryFileSystem::new(); 822 fs.write(&Utf8Path::new("/test/abc/def/wibble.erl"), "1") 823 .unwrap(); 824 fs.write(&Utf8Path::new("/test/abc/ghi/wibble_header.hrl"), "2") 825 .unwrap(); 826 fs.write(&Utf8Path::new("/test/def/wobble.ex"), "3") 827 .unwrap(); 828 829 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 830 let copied = copier.run().unwrap(); 831 832 assert!(copied.any_elixir); 833 assert_eq!( 834 copied.to_compile, 835 vec![ 836 Utf8PathBuf::from("abc/def/wibble.erl"), 837 Utf8PathBuf::from("def/wobble.ex") 838 ] 839 ); 840 assert_eq!( 841 HashMap::from([ 842 (Utf8PathBuf::from("/test/abc/def/wibble.erl"), "1".into()), 843 (Utf8PathBuf::from("/out/abc/def/wibble.erl"), "1".into()), 844 ( 845 Utf8PathBuf::from("/test/abc/ghi/wibble_header.hrl"), 846 "2".into() 847 ), 848 ( 849 Utf8PathBuf::from("/out/abc/ghi/wibble_header.hrl"), 850 "2".into() 851 ), 852 (Utf8PathBuf::from("/test/def/wobble.ex"), "3".into()), 853 (Utf8PathBuf::from("/out/def/wobble.ex"), "3".into()) 854 ]), 855 fs.into_contents(), 856 ); 857} 858 859#[test] 860fn all_erlang_files_are_copied_from_dev_subfolders() { 861 let fs = InMemoryFileSystem::new(); 862 fs.write(&Utf8Path::new("/dev/abc/def/wibble.erl"), "1") 863 .unwrap(); 864 fs.write(&Utf8Path::new("/dev/abc/ghi/wibble_header.hrl"), "2") 865 .unwrap(); 866 fs.write(&Utf8Path::new("/dev/def/wobble.ex"), "3").unwrap(); 867 868 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 869 let copied = copier.run().unwrap(); 870 871 assert!(copied.any_elixir); 872 assert_eq!( 873 copied.to_compile, 874 vec![ 875 Utf8PathBuf::from("abc/def/wibble.erl"), 876 Utf8PathBuf::from("def/wobble.ex") 877 ] 878 ); 879 assert_eq!( 880 HashMap::from([ 881 (Utf8PathBuf::from("/dev/abc/def/wibble.erl"), "1".into()), 882 (Utf8PathBuf::from("/out/abc/def/wibble.erl"), "1".into()), 883 ( 884 Utf8PathBuf::from("/dev/abc/ghi/wibble_header.hrl"), 885 "2".into() 886 ), 887 ( 888 Utf8PathBuf::from("/out/abc/ghi/wibble_header.hrl"), 889 "2".into() 890 ), 891 (Utf8PathBuf::from("/dev/def/wobble.ex"), "3".into()), 892 (Utf8PathBuf::from("/out/def/wobble.ex"), "3".into()) 893 ]), 894 fs.into_contents(), 895 ); 896} 897 898#[test] 899fn other_files_are_ignored() { 900 let fs = InMemoryFileSystem::new(); 901 fs.write(&Utf8Path::new("/src/wibble.cpp"), "1").unwrap(); 902 903 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 904 let copied = copier.run().unwrap(); 905 906 assert!(!copied.any_elixir); 907 assert!(copied.to_compile.is_empty()); 908 assert_eq!( 909 HashMap::from([(Utf8PathBuf::from("/src/wibble.cpp"), "1".into())]), 910 fs.into_contents(), 911 ); 912} 913 914#[test] 915fn files_do_not_get_copied_if_there_already_is_a_new_version() { 916 let fs = InMemoryFileSystem::new(); 917 let out = Utf8Path::new("/out/wibble.mjs"); 918 let src = Utf8Path::new("/src/wibble.mjs"); 919 fs.write(&out, "in-out").unwrap(); 920 fs.write(&src, "in-src").unwrap(); 921 fs.set_modification_time(&out, UNIX_EPOCH + Duration::from_secs(1)); 922 fs.set_modification_time(&src, UNIX_EPOCH); 923 924 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 925 let copied = copier.run().unwrap(); 926 927 assert!(!copied.any_elixir); 928 assert!(copied.to_compile.is_empty()); 929 assert_eq!( 930 HashMap::from([ 931 (Utf8PathBuf::from("/src/wibble.mjs"), "in-src".into()), 932 (Utf8PathBuf::from("/out/wibble.mjs"), "in-out".into()) 933 ]), 934 fs.into_contents(), 935 ); 936} 937 938#[test] 939fn files_get_copied_if_the_previously_copied_version_is_older() { 940 let fs = InMemoryFileSystem::new(); 941 let out = Utf8Path::new("/out/wibble.mjs"); 942 let src = Utf8Path::new("/src/wibble.mjs"); 943 fs.write(&out, "in-out").unwrap(); 944 fs.write(&src, "in-src").unwrap(); 945 fs.set_modification_time(&out, UNIX_EPOCH); 946 fs.set_modification_time(&src, UNIX_EPOCH + Duration::from_secs(1)); 947 948 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 949 let copied = copier.run().unwrap(); 950 951 assert!(!copied.any_elixir); 952 assert!(copied.to_compile.is_empty()); 953 assert_eq!( 954 HashMap::from([ 955 (Utf8PathBuf::from("/src/wibble.mjs"), "in-src".into()), 956 (Utf8PathBuf::from("/out/wibble.mjs"), "in-src".into()) 957 ]), 958 fs.into_contents(), 959 ); 960} 961 962#[test] 963fn duplicate_native_files_result_in_an_error() { 964 let fs = InMemoryFileSystem::new(); 965 fs.write(&Utf8Path::new("/src/wibble.mjs"), "1").unwrap(); 966 fs.write(&Utf8Path::new("/test/wibble.mjs"), "1").unwrap(); 967 968 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 969 assert!(copier.run().is_err()); 970} 971 972#[test] 973fn conflicting_erlang_modules_in_src_result_in_an_error() { 974 let fs = InMemoryFileSystem::new(); 975 fs.write(&Utf8Path::new("/src/a/b/c/wibble.erl"), "1") 976 .unwrap(); 977 fs.write(&Utf8Path::new("/src/e/f/wibble.erl"), "1") 978 .unwrap(); 979 980 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 981 assert!(copier.run().is_err()); 982} 983 984#[test] 985fn conflicting_erlang_modules_in_src_and_test_result_in_an_error() { 986 let fs = InMemoryFileSystem::new(); 987 fs.write(&Utf8Path::new("/src/a/b/c/wibble.erl"), "1") 988 .unwrap(); 989 fs.write(&Utf8Path::new("/test/e/f/wibble.erl"), "1") 990 .unwrap(); 991 992 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 993 assert!(copier.run().is_err()); 994} 995 996#[test] 997fn conflicting_erlang_modules_in_src_and_dev_result_in_an_error() { 998 let fs = InMemoryFileSystem::new(); 999 fs.write(&Utf8Path::new("/src/a/b/c/wibble.erl"), "1") 1000 .unwrap(); 1001 fs.write(&Utf8Path::new("/dev/e/f/wibble.erl"), "1") 1002 .unwrap(); 1003 1004 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1005 assert!(copier.run().is_err()); 1006} 1007 1008#[test] 1009fn conflicting_erlang_modules_in_dev_and_test_result_in_an_error() { 1010 let fs = InMemoryFileSystem::new(); 1011 fs.write(&Utf8Path::new("/dev/a/b/c/wibble.erl"), "1") 1012 .unwrap(); 1013 fs.write(&Utf8Path::new("/test/e/f/wibble.erl"), "1") 1014 .unwrap(); 1015 1016 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1017 assert!(copier.run().is_err()); 1018} 1019 1020#[test] 1021fn conflicting_gleam_and_javascript_modules_result_in_an_error() { 1022 let fs = InMemoryFileSystem::new(); 1023 fs.write(&Utf8Path::new("/src/wibble.gleam"), "1").unwrap(); 1024 fs.write(&Utf8Path::new("/src/wibble.mjs"), "1").unwrap(); 1025 1026 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1027 assert!(copier.run().is_err()); 1028} 1029 1030#[test] 1031fn differently_nested_gleam_and_javascript_modules_with_same_name_are_ok() { 1032 let fs = InMemoryFileSystem::new(); 1033 fs.write(&Utf8Path::new("/src/a/b/c/wibble.gleam"), "1") 1034 .unwrap(); 1035 fs.write(&Utf8Path::new("/src/d/e/wibble.mjs"), "1") 1036 .unwrap(); 1037 1038 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1039 assert!(copier.run().is_ok()); 1040} 1041 1042#[test] 1043fn conflicting_gleam_and_erlang_modules_result_in_an_error() { 1044 let fs = InMemoryFileSystem::new(); 1045 fs.write(&Utf8Path::new("/src/wibble.gleam"), "1").unwrap(); 1046 fs.write(&Utf8Path::new("/src/wibble.erl"), "1").unwrap(); 1047 1048 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1049 assert!(copier.run().is_err()); 1050} 1051 1052#[test] 1053fn conflicting_nested_gleam_and_erlang_modules_result_in_an_error() { 1054 let fs = InMemoryFileSystem::new(); 1055 fs.write(&Utf8Path::new("/src/wibble/wobble.gleam"), "1") 1056 .unwrap(); 1057 fs.write(&Utf8Path::new("/src/wibble@wobble.erl"), "1") 1058 .unwrap(); 1059 1060 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1061 assert!(copier.run().is_err()); 1062} 1063 1064#[test] 1065fn conflicting_nested_gleam_file_does_not_conflict_with_root_erlang_file() { 1066 let fs = InMemoryFileSystem::new(); 1067 fs.write(&Utf8Path::new("/src/wibble/wobble.gleam"), "1") 1068 .unwrap(); 1069 fs.write(&Utf8Path::new("/src/wobble.erl"), "1").unwrap(); 1070 1071 let copier = NativeFileCopier::new(fs.clone(), root(), root_out(), CheckModuleConflicts::Check); 1072 assert!(copier.run().is_ok()); 1073} 1074 1075#[test] 1076fn conflicting_gleam_and_erlang_modules_produce_no_error_in_dependency() { 1077 let fs = InMemoryFileSystem::new(); 1078 fs.write(&Utf8Path::new("/src/wibble.gleam"), "1").unwrap(); 1079 fs.write(&Utf8Path::new("/src/wibble.erl"), "1").unwrap(); 1080 1081 let copier = NativeFileCopier::new( 1082 fs.clone(), 1083 root(), 1084 root_out(), 1085 CheckModuleConflicts::DoNotCheck, 1086 ); 1087 assert!(copier.run().is_ok()); 1088}