Skip to content

Commit c4c98f3

Browse files
committed
Add tests
1 parent e772c05 commit c4c98f3

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

crates/uv/tests/common/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ impl TestContext {
9393
self.assert_command(
9494
format!("import {package} as package; print(package.__version__, end='')").as_str(),
9595
)
96-
.success()
97-
.stdout(version);
96+
.success()
97+
.stdout(version);
9898
}
9999
}
100100

@@ -218,7 +218,7 @@ pub fn create_bin_with_executables(
218218
&Platform::current().unwrap(),
219219
&Cache::temp().unwrap(),
220220
)?
221-
.ok_or(uv_interpreter::Error::NoSuchPython(request.to_string()))?;
221+
.ok_or(uv_interpreter::Error::NoSuchPython(request.to_string()))?;
222222
let name = interpreter
223223
.sys_executable()
224224
.file_name()
@@ -244,7 +244,7 @@ pub fn run_and_format<'a>(
244244
let output = command
245245
.borrow_mut()
246246
.output()
247-
.unwrap_or_else(|_| panic!("Failed to spawn {program}"));
247+
.unwrap_or_else(|err| panic!("Failed to spawn {program}: {err}"));
248248

249249
let mut snapshot = format!(
250250
"success: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}",

crates/uv/tests/pip_install.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg(all(feature = "python", feature = "pypi"))]
22

3+
use std::io::ErrorKind;
34
use std::process::Command;
45

56
use anyhow::Result;
@@ -1391,3 +1392,95 @@ fn direct_url_zip_file_bunk_permissions() -> Result<()> {
13911392

13921393
Ok(())
13931394
}
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+
}
Binary file not shown.

0 commit comments

Comments
 (0)