|
1 | 1 | #![cfg(all(feature = "python", feature = "pypi"))]
|
2 | 2 |
|
| 3 | +use std::io::ErrorKind; |
3 | 4 | use std::process::Command;
|
4 | 5 |
|
5 | 6 | use anyhow::Result;
|
@@ -1391,3 +1392,95 @@ fn direct_url_zip_file_bunk_permissions() -> Result<()> {
|
1391 | 1392 |
|
1392 | 1393 | Ok(())
|
1393 | 1394 | }
|
| 1395 | + |
| 1396 | +#[test] |
| 1397 | +fn entrypoint_script() -> Result<()> { |
| 1398 | + let context = TestContext::new("3.12"); |
| 1399 | + let project_root = fs_err::canonicalize(std::env::current_dir()?.join("../.."))?; |
| 1400 | + |
| 1401 | + uv_snapshot!(command(&context) |
| 1402 | + .arg(format!("simple_launcher@{}", project_root.join("scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl").display())) |
| 1403 | + .arg("--strict"), @r###" |
| 1404 | + success: true |
| 1405 | + exit_code: 0 |
| 1406 | + ----- stdout ----- |
| 1407 | +
|
| 1408 | + ----- stderr ----- |
| 1409 | + Resolved 1 package in [TIME] |
| 1410 | + Downloaded 1 package in [TIME] |
| 1411 | + Installed 1 package in [TIME] |
| 1412 | + + simple-launcher==0.1.0 (from file:///C:/Users/Micha/astral/puffin/scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl) |
| 1413 | + "### |
| 1414 | + ); |
| 1415 | + |
| 1416 | + let bin_path = if cfg!(windows) { "Scripts" } else { "bin" }; |
| 1417 | + |
| 1418 | + uv_snapshot!(Command::new( |
| 1419 | + context.venv.join(bin_path).join("simple_launcher") |
| 1420 | + ), @r###" |
| 1421 | + success: true |
| 1422 | + exit_code: 0 |
| 1423 | + ----- stdout ----- |
| 1424 | + Hi from the simple launcher! |
| 1425 | +
|
| 1426 | + ----- stderr ----- |
| 1427 | + "###); |
| 1428 | + |
| 1429 | + Ok(()) |
| 1430 | +} |
| 1431 | + |
| 1432 | +#[test] |
| 1433 | +fn entrypoint_script_symlink() -> Result<()> { |
| 1434 | + let context = TestContext::new("3.12"); |
| 1435 | + let project_root = fs_err::canonicalize(std::env::current_dir()?.join("../.."))?; |
| 1436 | + |
| 1437 | + uv_snapshot!(command(&context) |
| 1438 | + .arg(format!("simple_launcher@{}", project_root.join("scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl").display())) |
| 1439 | + .arg("--strict"), @r###" |
| 1440 | + success: true |
| 1441 | + exit_code: 0 |
| 1442 | + ----- stdout ----- |
| 1443 | +
|
| 1444 | + ----- stderr ----- |
| 1445 | + Resolved 1 package in [TIME] |
| 1446 | + Downloaded 1 package in [TIME] |
| 1447 | + Installed 1 package in [TIME] |
| 1448 | + + simple-launcher==0.1.0 (from file:///C:/Users/Micha/astral/puffin/scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl) |
| 1449 | + "### |
| 1450 | + ); |
| 1451 | + |
| 1452 | + #[cfg(windows)] |
| 1453 | + if let Err(error) = std::os::windows::fs::symlink_file( |
| 1454 | + context.venv.join("Scripts\\simple_launcher.exe"), |
| 1455 | + context.temp_dir.join("simple_launcher.exe"), |
| 1456 | + ) { |
| 1457 | + if error.kind() == ErrorKind::PermissionDenied { |
| 1458 | + // Not running as an administrator or developer mode isn't enabled. |
| 1459 | + // Ignore the test |
| 1460 | + return Ok(()); |
| 1461 | + } |
| 1462 | + } |
| 1463 | + |
| 1464 | + #[cfg(unix)] |
| 1465 | + std::os::unix::fs::symlink( |
| 1466 | + context.venv.join("bin/simple_launcher"), |
| 1467 | + context.temp_dir.join("simple_launcher"), |
| 1468 | + )?; |
| 1469 | + |
| 1470 | + // Only support windows or linux |
| 1471 | + #[cfg(not(any(windows, unix)))] |
| 1472 | + return Ok(()); |
| 1473 | + |
| 1474 | + uv_snapshot!(Command::new( |
| 1475 | + context.temp_dir.join("simple_launcher") |
| 1476 | + ), @r###" |
| 1477 | + success: true |
| 1478 | + exit_code: 0 |
| 1479 | + ----- stdout ----- |
| 1480 | + Hi from the simple launcher! |
| 1481 | +
|
| 1482 | + ----- stderr ----- |
| 1483 | + "###); |
| 1484 | + |
| 1485 | + Ok(()) |
| 1486 | +} |
0 commit comments