2017-01-30 17:38:11 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2017-02-19 11:10:16 +00:00
|
|
|
import rust2rpm
|
2017-02-05 20:06:40 +00:00
|
|
|
|
2017-01-30 17:38:11 +00:00
|
|
|
DUMMY_LIB = """
|
|
|
|
pub fn say_hello() {
|
|
|
|
println!("Hello, World!");
|
|
|
|
}
|
|
|
|
"""
|
2017-01-30 22:21:21 +00:00
|
|
|
DEPGEN = os.path.join(os.path.dirname(__file__), "cargodeps.py")
|
2017-01-30 17:38:11 +00:00
|
|
|
|
|
|
|
|
2017-02-19 11:10:16 +00:00
|
|
|
@pytest.mark.parametrize("req, features, rpmdep", [
|
|
|
|
("=1.0.0", [],
|
|
|
|
"crate(test) = 1.0.0"),
|
|
|
|
("=1.0.0", ["feature"],
|
|
|
|
"(crate(test) = 1.0.0 with crate(test/feature))"),
|
|
|
|
(">=1.0.0,<2.0.0", [],
|
|
|
|
"(crate(test) >= 1.0.0 with crate(test) < 2.0.0)"),
|
|
|
|
(">=1.0.0,<2.0.0", ["feature"],
|
|
|
|
"((crate(test) >= 1.0.0 with crate(test) < 2.0.0) with crate(test/feature))"),
|
|
|
|
])
|
|
|
|
def test_dependency(req, features, rpmdep):
|
|
|
|
dep = rust2rpm.Dependency("test", req, features)
|
|
|
|
assert str(dep) == rpmdep
|
|
|
|
|
2017-01-30 17:38:11 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def cargo_toml(request):
|
|
|
|
def make_cargo_toml(contents):
|
|
|
|
toml = os.path.join(tmpdir, "Cargo.toml")
|
|
|
|
with open(toml, "w") as fobj:
|
|
|
|
fobj.write(textwrap.dedent(contents))
|
|
|
|
return toml
|
|
|
|
|
|
|
|
tmpdir = tempfile.mkdtemp(prefix="cargo-deps-")
|
|
|
|
srcdir = os.path.join(tmpdir, "src")
|
|
|
|
os.mkdir(srcdir)
|
|
|
|
with open(os.path.join(srcdir, "lib.rs"), "w") as fobj:
|
|
|
|
fobj.write(DUMMY_LIB)
|
|
|
|
|
|
|
|
def finalize():
|
|
|
|
shutil.rmtree(tmpdir)
|
|
|
|
request.addfinalizer(finalize)
|
|
|
|
|
|
|
|
return make_cargo_toml
|
|
|
|
|
2017-02-19 11:10:16 +00:00
|
|
|
@pytest.mark.parametrize("toml, provides, requires", [
|
2017-01-30 17:38:16 +00:00
|
|
|
|
|
|
|
# Basic provides
|
2017-01-30 17:38:11 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
""",
|
2017-01-30 17:38:16 +00:00
|
|
|
["crate(hello) = 0.0.0"],
|
|
|
|
[]),
|
|
|
|
|
|
|
|
# Basic provides for feature
|
2017-01-30 17:38:11 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "1.2.3"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
color = []
|
|
|
|
""",
|
|
|
|
["crate(hello) = 1.2.3",
|
2017-01-30 17:38:16 +00:00
|
|
|
"crate(hello/color) = 1.2.3"],
|
|
|
|
[]),
|
|
|
|
|
|
|
|
# Caret requirements
|
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^0"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 0.0.0 with crate(libc) < 1.0.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^0.0"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 0.0.0 with crate(libc) < 0.1.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^0.0.3"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 0.0.3 with crate(libc) < 0.0.4)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^0.2.3"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 0.2.3 with crate(libc) < 0.3.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^1"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.0.0 with crate(libc) < 2.0.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^1.2"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.2.0 with crate(libc) < 2.0.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "^1.2.3"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.2.3 with crate(libc) < 2.0.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
|
|
|
|
# Tilde requirements
|
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "~1"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.0.0 with crate(libc) < 2.0.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "~1.2"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.2.0 with crate(libc) < 1.3.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "~1.2.3"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.2.3 with crate(libc) < 1.3.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
|
|
|
|
# Wildcard requirements
|
2017-02-26 16:06:24 +00:00
|
|
|
("""
|
2017-01-30 17:38:16 +00:00
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "*"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-26 16:06:24 +00:00
|
|
|
["crate(libc)"]),
|
|
|
|
("""
|
2017-01-30 17:38:16 +00:00
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "1.*"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-26 16:06:24 +00:00
|
|
|
["(crate(libc) >= 1.0.0 with crate(libc) < 2.0.0)"]),
|
|
|
|
("""
|
2017-01-30 17:38:16 +00:00
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "1.2.*"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-26 16:06:24 +00:00
|
|
|
["(crate(libc) >= 1.2.0 with crate(libc) < 1.3.0)"]),
|
2017-07-07 21:45:13 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "1.*.*"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
|
|
|
["(crate(libc) >= 1.0.0 with crate(libc) < 2.0.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
|
|
|
|
# Inequality requirements
|
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = ">= 1.2.0"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["crate(libc) >= 1.2.0"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "> 1"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["crate(libc) > 1.0.0"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "< 2"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["crate(libc) < 2.0.0"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = "= 1.2.3"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["crate(libc) = 1.2.3"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
|
|
|
|
# Multiple requirements
|
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
libc = ">= 1.2, < 1.5"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0"],
|
2017-02-19 11:10:16 +00:00
|
|
|
["(crate(libc) >= 1.2.0 with crate(libc) < 1.5.0)"]),
|
2017-01-30 17:38:16 +00:00
|
|
|
|
2017-05-17 23:40:01 +00:00
|
|
|
# Pre-release requirements
|
|
|
|
("""
|
|
|
|
[package]
|
|
|
|
name = "hello"
|
|
|
|
version = "0.0.0-alpha"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foo-bar = "1.2.3-beta"
|
|
|
|
""",
|
|
|
|
["crate(hello) = 0.0.0~alpha"],
|
|
|
|
["(crate(foo-bar) >= 1.2.3~beta with crate(foo-bar) < 1.2.3)"]),
|
|
|
|
|
2017-01-30 17:38:11 +00:00
|
|
|
])
|
2017-02-19 11:10:16 +00:00
|
|
|
def test_depgen(toml, provides, requires, cargo_toml):
|
|
|
|
md = rust2rpm.Metadata.from_file(cargo_toml(toml))
|
2017-02-05 20:06:40 +00:00
|
|
|
assert [str(x) for x in md.provides] == provides
|
|
|
|
assert [str(x) for x in md.requires] == requires
|