1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
extern crate debcargo;
use debcargo::config::{Config, PackageKey};
use std::path::Path;
#[test]
fn source_package_override() {
let filepath = Path::new("tests/clap_override.toml");
let config = Config::parse(filepath);
assert!(config.is_ok());
let config = config.unwrap();
assert!(config.source.is_some());
assert_eq!(config.packages.len(), 1);
let policy = config.policy_version();
assert!(policy.is_some());
assert_eq!(policy.unwrap(), "4.0.0");
let homepage = config.homepage();
assert!(homepage.is_some());
assert_eq!(homepage.unwrap(), "https://clap.rs");
assert!(config.section().is_none());
assert!(config.build_depends().is_none());
let filepath = Path::new("tests/debcargo_override.toml");
let config = Config::parse(filepath);
assert!(config.is_ok());
let config = config.unwrap();
assert!(config.source.is_some());
let section = config.section();
assert!(section.is_some());
assert_eq!(section.unwrap(), "rust");
assert_eq!(config.packages.len(), 1);
let sd = config.package_summary(PackageKey::Bin);
assert!(sd.is_some());
if let Some(s) = sd {
assert_eq!(s, "Tool to create Debian package from Rust crate");
}
let sd = config.package_description(PackageKey::Bin);
assert!(sd.is_some());
if let Some(d) = sd {
assert_eq!(
d,
"\
This package provides debcargo a tool to create Debian source package from \
Rust
crate. The package created by this tool is as per the packaging policy \
set by
Debian Rust team.
"
);
}
}
#[test]
fn binary_package_override() {
let filepath = Path::new("tests/tiny-dfr_override.toml");
let config = Config::parse(filepath);
assert!(config.is_ok());
let config = config.unwrap();
assert_eq!(config.packages.len(), 1);
assert_eq!(
config.package_summary(PackageKey::Bin),
Some("dynamic touch bar daemon")
);
assert_eq!(
config.package_description(PackageKey::Bin),
Some(
"\
This package contains tiny-dfr, the userland touch bar daemon.
tiny-dfr shows the function row and media control keys (brightness,
volume, backlight, play, etc) on your touch bar. Currently supported
platforms are Apple Silicon and T2 Macs.
"
)
);
assert_eq!(
config.package_architecture(PackageKey::Bin),
Some(&vec!["arm64".to_string(), "amd64".to_string()])
);
}
#[test]
fn sd_top_level() {
let filepath = Path::new("tests/debcargo_override_top_level.toml");
let config = Config::parse(filepath);
assert!(config.is_ok());
let config = config.unwrap();
assert!(config.source.is_some());
let section = config.section();
assert!(section.is_some());
assert_eq!(section.unwrap(), "rust");
assert_eq!(
config.summary.unwrap(),
"Tool to create Debian package from Rust crate"
);
assert_eq!(
config.description.unwrap(),
"\
This package provides debcargo a tool to create Debian source package from \
Rust
crate. The package created by this tool is as per the packaging policy \
set by
Debian Rust team.
"
);
}
#[test]
fn unknown_fields_captured_with_warning() {
use std::fs::File;
use std::io::Write;
use tempfile::tempdir;
let dir = tempdir().unwrap();
let file_path = dir.path().join("test_debcargo.toml");
// Test unknown field at top level
let mut file = File::create(&file_path).unwrap();
writeln!(
file,
r#"
semver_suffix = true
overlay = "."
verlay = "typo" # This should be captured as an unknown field
"#
)
.unwrap();
drop(file);
let result = Config::parse(&file_path);
assert!(result.is_ok());
let config = result.unwrap();
assert!(config.unknown_fields.contains_key("verlay"));
// Test unknown field in source section
let mut file = File::create(&file_path).unwrap();
writeln!(
file,
r#"
[source]
section = "rust"
unknown_field = "value"
"#
)
.unwrap();
drop(file);
let result = Config::parse(&file_path);
assert!(result.is_ok());
let config = result.unwrap();
assert!(config.source.is_some());
if let Some(source) = config.source {
assert!(source.unknown_fields.contains_key("unknown_field"));
}
// Test unknown field in packages section
let mut file = File::create(&file_path).unwrap();
writeln!(
file,
r#"
[packages.lib]
section = "libs"
unknwon_field = "value"
"#
)
.unwrap();
drop(file);
let result = Config::parse(&file_path);
assert!(result.is_ok());
let config = result.unwrap();
assert!(config.packages.contains_key("lib"));
if let Some(lib_package) = config.packages.get("lib") {
assert!(lib_package.unknown_fields.contains_key("unknwon_field"));
}
}
|