File: config_tests.rs

package info (click to toggle)
rust-debcargo 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,788 kB
  • sloc: sh: 241; makefile: 90
file content (158 lines) | stat: -rw-r--r-- 4,217 bytes parent folder | download
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
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).unwrap();

    assert!(config.source.is_some());
    assert_eq!(config.packages.len(), 1);

    assert_eq!(config.policy_version().unwrap(), "4.0.0");

    assert_eq!(config.homepage().unwrap(), "https://clap.rs");

    assert_eq!(config.section(), None);
    assert_eq!(config.build_depends(), None);

    let filepath = Path::new("tests/debcargo_override.toml");
    let config = Config::parse(filepath).unwrap();

    assert!(config.source.is_some());

    assert_eq!(config.section().unwrap(), "rust");

    assert_eq!(config.packages.len(), 2);
    assert_eq!(
        config.package_summary(PackageKey::Bin).unwrap(),
        "Tool to create Debian package from Rust crate"
    );

    assert_eq!(
        config.package_description(PackageKey::Bin).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.
"
    );

    let extra = PackageKey::Extra("libblake3-0");
    assert_eq!(config.package_architecture(extra).unwrap(), &vec!["any"]);
    assert_eq!(config.package_section(extra).unwrap(), "libs");
    assert_eq!(
        config.package_depends(extra).unwrap(),
        &vec!["${misc:Depends}", "${shlibs:Depends}"]
    );
    assert_eq!(
        config.package_description(extra).unwrap(),
        "BLAKE3 hash function - C library"
    );
}

#[test]
fn binary_package_override() {
    let filepath = Path::new("tests/tiny-dfr_override.toml");
    let config = Config::parse(filepath).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).unwrap();

    assert!(config.source.is_some());

    assert_eq!(config.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() {
    let file_path = Path::new(env!("CARGO_TARGET_TMPDIR")).join("test_debcargo.toml");

    // Test unknown field at top level
    std::fs::write(
        &file_path,
        br#"
semver_suffix = true
overlay = "."
verlay = "typo"  # This should be captured as an unknown field
"#,
    )
    .unwrap();

    let config = Config::parse(&file_path).unwrap();
    assert!(config.unknown_fields.contains_key("verlay"));

    // Test unknown field in source section
    std::fs::write(
        &file_path,
        r#"
[source]
section = "rust"
unknown_field = "value"
"#,
    )
    .unwrap();

    let config = Config::parse(&file_path).unwrap();
    let source = config.source.unwrap();
    assert!(source.unknown_fields.contains_key("unknown_field"));

    // Test unknown field in packages section
    std::fs::write(
        &file_path,
        r#"
[packages.lib]
section = "libs"
unknwon_field = "value"
"#,
    )
    .unwrap();

    let config = Config::parse(&file_path).unwrap();
    let lib_package = config.packages.get("lib").unwrap();
    assert!(lib_package.unknown_fields.contains_key("unknwon_field"));
}