mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 13:43:45 +00:00
chore: Move all integration tests to a single binary (#8093)
As per https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html Before that, there were 91 separate integration tests binary. (As discussed on Discord — I've done the `uv` crate, there's still a few more commits coming before this is mergeable, and I want to see how it performs in CI and locally).
This commit is contained in:
parent
fce7a838e9
commit
715f28fd39
231 changed files with 15585 additions and 15507 deletions
|
@ -481,233 +481,4 @@ fn serialize_metadata(metadata: &str) -> String {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{serialize_metadata, Pep723Error, ScriptTag};
|
||||
|
||||
#[test]
|
||||
fn missing_space() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
#requires-python = '>=3.11'
|
||||
# ///
|
||||
"};
|
||||
|
||||
assert!(matches!(
|
||||
ScriptTag::parse(contents.as_bytes()),
|
||||
Err(Pep723Error::UnclosedBlock)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_closing_pragma() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
"};
|
||||
|
||||
assert!(matches!(
|
||||
ScriptTag::parse(contents.as_bytes()),
|
||||
Err(Pep723Error::UnclosedBlock)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_content() {
|
||||
let contents = indoc::indoc! {r"
|
||||
pass # /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
#
|
||||
#
|
||||
"};
|
||||
|
||||
assert_eq!(ScriptTag::parse(contents.as_bytes()).unwrap(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let expected_metadata = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let expected_data = indoc::indoc! {r"
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes()).unwrap().unwrap();
|
||||
|
||||
assert_eq!(actual.prelude, String::new());
|
||||
assert_eq!(actual.metadata, expected_metadata);
|
||||
assert_eq!(actual.postlude, expected_data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_with_shebang() {
|
||||
let contents = indoc::indoc! {r"
|
||||
#!/usr/bin/env python3
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let expected_metadata = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let expected_data = indoc::indoc! {r"
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes()).unwrap().unwrap();
|
||||
|
||||
assert_eq!(actual.prelude, "#!/usr/bin/env python3\n".to_string());
|
||||
assert_eq!(actual.metadata, expected_metadata);
|
||||
assert_eq!(actual.postlude, expected_data);
|
||||
}
|
||||
#[test]
|
||||
fn embedded_comment() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# embedded-csharp = '''
|
||||
# /// <summary>
|
||||
# /// text
|
||||
# ///
|
||||
# /// </summary>
|
||||
# public class MyClass { }
|
||||
# '''
|
||||
# ///
|
||||
"};
|
||||
|
||||
let expected = indoc::indoc! {r"
|
||||
embedded-csharp = '''
|
||||
/// <summary>
|
||||
/// text
|
||||
///
|
||||
/// </summary>
|
||||
public class MyClass { }
|
||||
'''
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata;
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_lines() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
#
|
||||
#
|
||||
"};
|
||||
|
||||
let expected = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata;
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_metadata_formatting() {
|
||||
let metadata = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let expected_output = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
"};
|
||||
|
||||
let result = serialize_metadata(metadata);
|
||||
assert_eq!(result, expected_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_metadata_empty() {
|
||||
let metadata = "";
|
||||
let expected_output = "# /// script\n# ///\n";
|
||||
|
||||
let result = serialize_metadata(metadata);
|
||||
assert_eq!(result, expected_output);
|
||||
}
|
||||
}
|
||||
mod tests;
|
||||
|
|
228
crates/uv-scripts/src/tests.rs
Normal file
228
crates/uv-scripts/src/tests.rs
Normal file
|
@ -0,0 +1,228 @@
|
|||
use crate::{serialize_metadata, Pep723Error, ScriptTag};
|
||||
|
||||
#[test]
|
||||
fn missing_space() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
#requires-python = '>=3.11'
|
||||
# ///
|
||||
"};
|
||||
|
||||
assert!(matches!(
|
||||
ScriptTag::parse(contents.as_bytes()),
|
||||
Err(Pep723Error::UnclosedBlock)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_closing_pragma() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
"};
|
||||
|
||||
assert!(matches!(
|
||||
ScriptTag::parse(contents.as_bytes()),
|
||||
Err(Pep723Error::UnclosedBlock)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_content() {
|
||||
let contents = indoc::indoc! {r"
|
||||
pass # /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
#
|
||||
#
|
||||
"};
|
||||
|
||||
assert_eq!(ScriptTag::parse(contents.as_bytes()).unwrap(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let expected_metadata = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let expected_data = indoc::indoc! {r"
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes()).unwrap().unwrap();
|
||||
|
||||
assert_eq!(actual.prelude, String::new());
|
||||
assert_eq!(actual.metadata, expected_metadata);
|
||||
assert_eq!(actual.postlude, expected_data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_with_shebang() {
|
||||
let contents = indoc::indoc! {r"
|
||||
#!/usr/bin/env python3
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let expected_metadata = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let expected_data = indoc::indoc! {r"
|
||||
|
||||
import requests
|
||||
from rich.pretty import pprint
|
||||
|
||||
resp = requests.get('https://peps.python.org/api/peps.json')
|
||||
data = resp.json()
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes()).unwrap().unwrap();
|
||||
|
||||
assert_eq!(actual.prelude, "#!/usr/bin/env python3\n".to_string());
|
||||
assert_eq!(actual.metadata, expected_metadata);
|
||||
assert_eq!(actual.postlude, expected_data);
|
||||
}
|
||||
#[test]
|
||||
fn embedded_comment() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# embedded-csharp = '''
|
||||
# /// <summary>
|
||||
# /// text
|
||||
# ///
|
||||
# /// </summary>
|
||||
# public class MyClass { }
|
||||
# '''
|
||||
# ///
|
||||
"};
|
||||
|
||||
let expected = indoc::indoc! {r"
|
||||
embedded-csharp = '''
|
||||
/// <summary>
|
||||
/// text
|
||||
///
|
||||
/// </summary>
|
||||
public class MyClass { }
|
||||
'''
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata;
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_lines() {
|
||||
let contents = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
#
|
||||
#
|
||||
"};
|
||||
|
||||
let expected = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let actual = ScriptTag::parse(contents.as_bytes())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata;
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_metadata_formatting() {
|
||||
let metadata = indoc::indoc! {r"
|
||||
requires-python = '>=3.11'
|
||||
dependencies = [
|
||||
'requests<3',
|
||||
'rich',
|
||||
]
|
||||
"};
|
||||
|
||||
let expected_output = indoc::indoc! {r"
|
||||
# /// script
|
||||
# requires-python = '>=3.11'
|
||||
# dependencies = [
|
||||
# 'requests<3',
|
||||
# 'rich',
|
||||
# ]
|
||||
# ///
|
||||
"};
|
||||
|
||||
let result = serialize_metadata(metadata);
|
||||
assert_eq!(result, expected_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_metadata_empty() {
|
||||
let metadata = "";
|
||||
let expected_output = "# /// script\n# ///\n";
|
||||
|
||||
let result = serialize_metadata(metadata);
|
||||
assert_eq!(result, expected_output);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue