2022-03-26 09:42:19 +00:00
|
|
|
use super::{Context, Module, ModuleConfig};
|
2020-07-07 22:45:32 +00:00
|
|
|
use crate::configs::package::PackageConfig;
|
2021-08-06 19:16:14 +00:00
|
|
|
use crate::formatter::{StringFormatter, VersionFormatter};
|
2019-05-01 20:34:24 +00:00
|
|
|
|
2021-07-27 15:58:35 +00:00
|
|
|
use ini::Ini;
|
2020-07-31 07:54:03 +00:00
|
|
|
use quick_xml::events::Event as QXEvent;
|
|
|
|
use quick_xml::Reader as QXReader;
|
2020-02-21 19:12:21 +00:00
|
|
|
use regex::Regex;
|
2019-06-10 14:56:17 +00:00
|
|
|
use serde_json as json;
|
2019-05-01 14:45:56 +00:00
|
|
|
|
2019-07-19 20:18:52 +00:00
|
|
|
/// Creates a module with the current package version
|
2019-07-02 20:12:53 +00:00
|
|
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
2020-04-28 08:53:30 +00:00
|
|
|
let mut module = context.new_module("package");
|
|
|
|
let config: PackageConfig = PackageConfig::try_load(module.config);
|
2021-08-06 19:16:14 +00:00
|
|
|
let module_version = get_version(context, &config)?;
|
2019-10-19 01:51:38 +00:00
|
|
|
|
2020-07-07 22:45:32 +00:00
|
|
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
|
|
|
formatter
|
|
|
|
.map_meta(|var, _| match var {
|
|
|
|
"symbol" => Some(config.symbol),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.map_style(|variable| match variable {
|
|
|
|
"style" => Some(Ok(config.style)),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.map(|variable| match variable {
|
|
|
|
"version" => Some(Ok(&module_version)),
|
|
|
|
_ => None,
|
|
|
|
})
|
2021-11-01 21:18:45 +00:00
|
|
|
.parse(None, Some(context))
|
2020-07-07 22:45:32 +00:00
|
|
|
});
|
2019-05-01 14:45:56 +00:00
|
|
|
|
2020-07-07 22:45:32 +00:00
|
|
|
module.set_segments(match parsed {
|
|
|
|
Ok(segments) => segments,
|
|
|
|
Err(error) => {
|
|
|
|
log::warn!("Error in module `package`:\n{}", error);
|
|
|
|
return None;
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|
2020-07-07 22:45:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Some(module)
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_node_package_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("package.json")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
let package_json: json::Value = json::from_str(&file_contents).ok()?;
|
2021-05-09 04:38:16 +00:00
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
if !config.display_private
|
|
|
|
&& package_json.get("private").and_then(json::Value::as_bool) == Some(true)
|
2020-04-28 08:53:30 +00:00
|
|
|
{
|
2020-03-05 15:49:11 +00:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:06:34 +00:00
|
|
|
let raw_version = package_json.get("version")?.as_str()?;
|
|
|
|
if raw_version == "null" {
|
|
|
|
return None;
|
|
|
|
};
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
let formatted_version = format_version(raw_version, config.version_format)?;
|
2021-04-29 19:06:25 +00:00
|
|
|
if formatted_version == "v0.0.0-development" || formatted_version.starts_with("v0.0.0-semantic")
|
|
|
|
{
|
|
|
|
return Some("semantic".to_string());
|
|
|
|
};
|
|
|
|
|
2019-05-16 16:06:34 +00:00
|
|
|
Some(formatted_version)
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 16:44:01 +00:00
|
|
|
fn get_poetry_version(pyproject: &toml::Value) -> Option<&str> {
|
|
|
|
pyproject
|
2019-08-15 20:41:06 +00:00
|
|
|
.get("tool")?
|
|
|
|
.get("poetry")?
|
|
|
|
.get("version")?
|
2022-05-02 16:44:01 +00:00
|
|
|
.as_str()
|
|
|
|
}
|
2019-08-15 20:41:06 +00:00
|
|
|
|
2022-05-02 16:44:01 +00:00
|
|
|
fn get_pep621_version(pyproject: &toml::Value) -> Option<&str> {
|
|
|
|
pyproject.get("project")?.get("version")?.as_str()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_pyproject_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
|
|
|
let file_contents = context.read_file_from_pwd("pyproject.toml")?;
|
|
|
|
let pyproject_toml: toml::Value = toml::from_str(&file_contents).ok()?;
|
|
|
|
|
|
|
|
get_pep621_version(&pyproject_toml)
|
|
|
|
.or_else(|| get_poetry_version(&pyproject_toml))
|
|
|
|
.and_then(|raw_version| format_version(raw_version, config.version_format))
|
2019-08-15 20:41:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_setup_cfg_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("setup.cfg")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
let ini = Ini::load_from_str(&file_contents).ok()?;
|
2021-07-27 15:58:35 +00:00
|
|
|
let raw_version = ini.get_from(Some("metadata"), "version")?;
|
|
|
|
|
2021-09-14 17:17:05 +00:00
|
|
|
if raw_version.starts_with("attr:") || raw_version.starts_with("file:") {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
format_version(raw_version, config.version_format)
|
|
|
|
}
|
2021-07-27 15:58:35 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_gradle_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("build.gradle")?;
|
2020-02-21 19:12:21 +00:00
|
|
|
let re = Regex::new(r#"(?m)^version ['"](?P<version>[^'"]+)['"]$"#).unwrap();
|
2021-08-06 19:16:14 +00:00
|
|
|
let caps = re.captures(&file_contents)?;
|
2020-02-21 19:12:21 +00:00
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
format_version(&caps["version"], config.version_format)
|
2020-02-21 19:12:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_composer_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("composer.json")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
let composer_json: json::Value = json::from_str(&file_contents).ok()?;
|
2019-12-12 02:05:39 +00:00
|
|
|
let raw_version = composer_json.get("version")?.as_str()?;
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
format_version(raw_version, config.version_format)
|
2019-12-12 02:05:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_julia_project_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("Project.toml")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
let project_toml: toml::Value = toml::from_str(&file_contents).ok()?;
|
2020-04-03 18:16:22 +00:00
|
|
|
let raw_version = project_toml.get("version")?.as_str()?;
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
format_version(raw_version, config.version_format)
|
2020-04-03 18:16:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_helm_package_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("Chart.yaml")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
let yaml = yaml_rust::YamlLoader::load_from_str(&file_contents).ok()?;
|
2020-07-29 12:06:47 +00:00
|
|
|
let version = yaml.first()?["version"].as_str()?;
|
2021-08-06 19:16:14 +00:00
|
|
|
|
|
|
|
format_version(version, config.version_format)
|
2020-07-29 12:06:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_mix_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("mix.exs")?;
|
2020-04-08 16:39:54 +00:00
|
|
|
let re = Regex::new(r#"(?m)version: "(?P<version>[^"]+)""#).unwrap();
|
2021-08-06 19:16:14 +00:00
|
|
|
let caps = re.captures(&file_contents)?;
|
2020-04-08 16:39:54 +00:00
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
format_version(&caps["version"], config.version_format)
|
2020-04-08 16:39:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_maven_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("pom.xml")?;
|
|
|
|
let mut reader = QXReader::from_str(&file_contents);
|
2020-07-31 07:54:03 +00:00
|
|
|
reader.trim_text(true);
|
|
|
|
|
|
|
|
let mut buf = vec![];
|
|
|
|
let mut in_ver = false;
|
|
|
|
let mut depth = 0;
|
|
|
|
loop {
|
|
|
|
match reader.read_event(&mut buf) {
|
|
|
|
Ok(QXEvent::Start(ref e)) => {
|
|
|
|
in_ver = depth == 1 && e.name() == b"version";
|
|
|
|
depth += 1;
|
|
|
|
}
|
|
|
|
Ok(QXEvent::End(_)) => {
|
|
|
|
in_ver = false;
|
|
|
|
depth -= 1;
|
|
|
|
}
|
|
|
|
Ok(QXEvent::Text(t)) if in_ver => {
|
|
|
|
let ver = t.unescape_and_decode(&reader).ok();
|
|
|
|
return match ver {
|
|
|
|
// Ignore version which is just a property reference
|
2021-08-06 19:16:14 +00:00
|
|
|
Some(ref v) if !v.starts_with('$') => format_version(v, config.version_format),
|
2020-07-31 07:54:03 +00:00
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
Ok(QXEvent::Eof) => break,
|
|
|
|
Ok(_) => (),
|
|
|
|
|
|
|
|
Err(err) => {
|
|
|
|
log::warn!("Error parsing pom.xml`:\n{}", err);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_meson_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context
|
|
|
|
.read_file_from_pwd("meson.build")?
|
2021-08-06 19:16:14 +00:00
|
|
|
.split_ascii_whitespace()
|
|
|
|
.collect::<String>();
|
2020-12-19 13:17:34 +00:00
|
|
|
|
2021-03-12 14:30:25 +00:00
|
|
|
let re = Regex::new(r#"project\([^())]*,version:'(?P<version>[^']+)'[^())]*\)"#).unwrap();
|
2020-12-19 13:17:34 +00:00
|
|
|
let caps = re.captures(&file_contents)?;
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
format_version(&caps["version"], config.version_format)
|
2020-12-19 13:17:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_vmod_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("v.mod")?;
|
2021-05-07 14:22:18 +00:00
|
|
|
let re = Regex::new(r"(?m)^\s*version\s*:\s*'(?P<version>[^']+)'").unwrap();
|
2021-08-06 19:16:14 +00:00
|
|
|
let caps = re.captures(&file_contents)?;
|
|
|
|
format_version(&caps["version"], config.version_format)
|
2021-05-07 14:22:18 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_vpkg_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("vpkg.json")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
let vpkg_json: json::Value = json::from_str(&file_contents).ok()?;
|
|
|
|
let raw_version = vpkg_json.get("version")?.as_str()?;
|
|
|
|
|
|
|
|
format_version(raw_version, config.version_format)
|
2021-05-07 14:22:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 06:56:06 +00:00
|
|
|
fn get_sbt_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("build.sbt")?;
|
2021-12-03 06:56:06 +00:00
|
|
|
let re = Regex::new(r"(?m)^(.*/)*\s*version\s*:=\s*.(?P<version>[\d\.]+)").unwrap();
|
|
|
|
let caps = re.captures(&file_contents)?;
|
|
|
|
format_version(&caps["version"], config.version_format)
|
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_cargo_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("Cargo.toml")?;
|
2021-08-06 19:16:14 +00:00
|
|
|
|
|
|
|
let cargo_toml: toml::Value = toml::from_str(&file_contents).ok()?;
|
|
|
|
let raw_version = cargo_toml.get("package")?.get("version")?.as_str()?;
|
2021-05-09 04:38:16 +00:00
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
format_version(raw_version, config.version_format)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_nimble_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
|
|
|
if !context
|
2021-05-09 04:38:16 +00:00
|
|
|
.try_begin_scan()?
|
|
|
|
.set_extensions(&["nimble"])
|
|
|
|
.is_match()
|
|
|
|
{
|
2021-08-06 19:16:14 +00:00
|
|
|
return None;
|
|
|
|
};
|
|
|
|
|
|
|
|
let cmd_output = context.exec_cmd("nimble", &["dump", "--json"])?;
|
|
|
|
let nimble_json: json::Value = json::from_str(&cmd_output.stdout).ok()?;
|
|
|
|
|
|
|
|
let raw_version = nimble_json.get("version")?.as_str()?;
|
|
|
|
|
|
|
|
format_version(raw_version, config.version_format)
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 05:42:55 +00:00
|
|
|
fn get_shard_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("shard.yml")?;
|
2021-10-13 05:42:55 +00:00
|
|
|
|
|
|
|
let data = yaml_rust::YamlLoader::load_from_str(&file_contents).ok()?;
|
|
|
|
let raw_version = data.first()?["version"].as_str()?;
|
|
|
|
|
|
|
|
format_version(raw_version, config.version_format)
|
|
|
|
}
|
|
|
|
|
2022-05-26 14:42:31 +00:00
|
|
|
fn get_daml_project_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
|
|
|
let file_contents = context.read_file_from_pwd("daml.yaml")?;
|
|
|
|
|
|
|
|
let daml_yaml = yaml_rust::YamlLoader::load_from_str(&file_contents).ok()?;
|
|
|
|
let raw_version = daml_yaml.first()?["version"].as_str()?;
|
|
|
|
|
|
|
|
format_version(raw_version, config.version_format)
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:57:20 +00:00
|
|
|
fn get_dart_pub_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
2022-04-25 14:18:01 +00:00
|
|
|
let file_contents = context.read_file_from_pwd("pubspec.yaml")?;
|
2022-01-01 22:57:20 +00:00
|
|
|
|
|
|
|
let data = yaml_rust::YamlLoader::load_from_str(&file_contents).ok()?;
|
|
|
|
let raw_version = data.first()?["version"].as_str()?;
|
|
|
|
|
|
|
|
format_version(raw_version, config.version_format)
|
|
|
|
}
|
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
|
|
|
let package_version_fn: Vec<fn(&Context, &PackageConfig) -> Option<String>> = vec![
|
|
|
|
get_cargo_version,
|
|
|
|
get_nimble_version,
|
|
|
|
get_node_package_version,
|
2022-05-02 16:44:01 +00:00
|
|
|
get_pyproject_version,
|
2021-08-06 19:16:14 +00:00
|
|
|
get_setup_cfg_version,
|
|
|
|
get_composer_version,
|
|
|
|
get_gradle_version,
|
|
|
|
get_julia_project_version,
|
|
|
|
get_mix_version,
|
|
|
|
get_helm_package_version,
|
|
|
|
get_maven_version,
|
|
|
|
get_meson_version,
|
2021-10-13 05:42:55 +00:00
|
|
|
get_shard_version,
|
2021-08-06 19:16:14 +00:00
|
|
|
get_vmod_version,
|
|
|
|
get_vpkg_version,
|
2021-12-03 06:56:06 +00:00
|
|
|
get_sbt_version,
|
2022-05-26 14:42:31 +00:00
|
|
|
get_daml_project_version,
|
2022-01-01 22:57:20 +00:00
|
|
|
get_dart_pub_version,
|
2021-08-06 19:16:14 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
package_version_fn.iter().find_map(|f| f(context, config))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn format_version(version: &str, version_format: &str) -> Option<String> {
|
|
|
|
let cleaned = version
|
|
|
|
.replace('"', "")
|
|
|
|
.trim()
|
|
|
|
.trim_start_matches('v')
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
VersionFormatter::format_module_version("package", &cleaned, version_format)
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2021-05-09 04:38:16 +00:00
|
|
|
use crate::{test::ModuleRenderer, utils::CommandOutput};
|
2020-04-28 08:53:30 +00:00
|
|
|
use ansi_term::Color;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io;
|
|
|
|
use std::io::Write;
|
|
|
|
use tempfile::TempDir;
|
2019-05-01 14:45:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_format_version() {
|
2021-08-06 19:16:14 +00:00
|
|
|
let raw_expected = Some(String::from("v1.2.3"));
|
|
|
|
|
|
|
|
assert_eq!(format_version("1.2.3", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version(" 1.2.3 ", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version("1.2.3 ", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version(" 1.2.3", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version("\"1.2.3\"", "v${raw}"), raw_expected);
|
|
|
|
|
|
|
|
assert_eq!(format_version("v1.2.3", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version(" v1.2.3 ", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version(" v1.2.3", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version("v1.2.3 ", "v${raw}"), raw_expected);
|
|
|
|
assert_eq!(format_version("\"v1.2.3\"", "v${raw}"), raw_expected);
|
|
|
|
|
|
|
|
let major_expected = Some(String::from("v1"));
|
|
|
|
assert_eq!(format_version("1.2.3", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version(" 1.2.3 ", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version("1.2.3 ", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version(" 1.2.3", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version("\"1.2.3\"", "v${major}"), major_expected);
|
2019-11-20 14:16:07 +00:00
|
|
|
|
2021-08-06 19:16:14 +00:00
|
|
|
assert_eq!(format_version("v1.2.3", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version(" v1.2.3 ", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version(" v1.2.3", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version("v1.2.3 ", "v${major}"), major_expected);
|
|
|
|
assert_eq!(format_version("\"v1.2.3\"", "v${major}"), major_expected);
|
2019-05-16 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_cargo_version() -> io::Result<()> {
|
|
|
|
let config_name = "Cargo.toml";
|
|
|
|
let config_content = toml::toml! {
|
2019-06-10 14:56:17 +00:00
|
|
|
[package]
|
|
|
|
name = "starship"
|
|
|
|
version = "0.1.0"
|
2019-07-02 20:12:53 +00:00
|
|
|
}
|
|
|
|
.to_string();
|
2019-05-16 16:06:34 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2019-05-16 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 04:38:16 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_nimble_package_version() -> io::Result<()> {
|
|
|
|
let config_name = "test_project.nimble";
|
|
|
|
|
|
|
|
let config_content = r##"
|
|
|
|
version = "0.1.0"
|
|
|
|
author = "Mr. nimble"
|
|
|
|
description = "A new awesome nimble package"
|
|
|
|
license = "MIT"
|
|
|
|
"##;
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-05-09 04:38:16 +00:00
|
|
|
|
|
|
|
let starship_config = toml::toml! {
|
|
|
|
[package]
|
|
|
|
disabled = false
|
|
|
|
};
|
|
|
|
let actual = ModuleRenderer::new("package")
|
|
|
|
.cmd(
|
|
|
|
"nimble dump --json",
|
|
|
|
Some(CommandOutput {
|
|
|
|
stdout: r##"
|
|
|
|
{
|
|
|
|
"name": "test_project.nimble",
|
|
|
|
"version": "0.1.0",
|
|
|
|
"author": "Mr. nimble",
|
|
|
|
"desc": "A new awesome nimble package",
|
|
|
|
"license": "MIT",
|
|
|
|
"skipDirs": [],
|
|
|
|
"skipFiles": [],
|
|
|
|
"skipExt": [],
|
|
|
|
"installDirs": [],
|
|
|
|
"installFiles": [],
|
|
|
|
"installExt": [],
|
|
|
|
"requires": [],
|
|
|
|
"bin": [],
|
|
|
|
"binDir": "",
|
|
|
|
"srcDir": "",
|
|
|
|
"backend": "c"
|
|
|
|
}
|
|
|
|
"##
|
|
|
|
.to_owned(),
|
|
|
|
stderr: "".to_owned(),
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.path(project_dir.path())
|
|
|
|
.config(starship_config)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let expected = Some(format!(
|
|
|
|
"is {} ",
|
|
|
|
Color::Fixed(208).bold().paint(format!("📦 {}", "v0.1.0"))
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_nimble_package_version_for_nimble_directory_when_nimble_is_not_available(
|
|
|
|
) -> io::Result<()> {
|
|
|
|
let config_name = "test_project.nimble";
|
|
|
|
|
|
|
|
let config_content = r##"
|
|
|
|
version = "0.1.0"
|
|
|
|
author = "Mr. nimble"
|
|
|
|
description = "A new awesome nimble package"
|
|
|
|
license = "MIT"
|
|
|
|
"##;
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-05-09 04:38:16 +00:00
|
|
|
|
|
|
|
let starship_config = toml::toml! {
|
|
|
|
[package]
|
|
|
|
disabled = false
|
|
|
|
};
|
|
|
|
let actual = ModuleRenderer::new("package")
|
|
|
|
.cmd("nimble dump --json", None)
|
|
|
|
.path(project_dir.path())
|
|
|
|
.config(starship_config)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let expected = None;
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_nimble_package_version_for_non_nimble_directory() -> io::Result<()> {
|
|
|
|
// Only create an empty directory. There's no .nibmle file for this case.
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
|
|
|
|
let starship_config = toml::toml! {
|
|
|
|
[package]
|
|
|
|
disabled = false
|
|
|
|
};
|
|
|
|
let actual = ModuleRenderer::new("package")
|
|
|
|
.cmd("nimble dump --json", None)
|
|
|
|
.path(project_dir.path())
|
|
|
|
.config(starship_config)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let expected = None;
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:06:34 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_package_version() -> io::Result<()> {
|
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
2019-05-16 16:06:34 +00:00
|
|
|
"version": "0.1.0"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2020-03-05 15:49:11 +00:00
|
|
|
}
|
2019-05-16 16:06:34 +00:00
|
|
|
|
2020-03-05 15:49:11 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_package_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship"
|
2019-05-16 16:06:34 +00:00
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|
2019-08-15 20:41:06 +00:00
|
|
|
|
2020-03-05 15:49:11 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_package_version_with_null_version() -> io::Result<()> {
|
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
2020-03-05 15:49:11 +00:00
|
|
|
"version": null
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2020-03-05 15:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_package_version_with_null_string_version() -> io::Result<()> {
|
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
2020-03-05 15:49:11 +00:00
|
|
|
"version": "null"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2020-03-05 15:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_private_package_version_with_default_config() -> io::Result<()> {
|
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
2020-03-05 15:49:11 +00:00
|
|
|
"version": "0.1.0",
|
|
|
|
"private": true
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2020-03-05 15:49:11 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 20:41:06 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_private_package_version_with_display_private() -> io::Result<()> {
|
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
|
|
|
"version": "0.1.0",
|
|
|
|
"private": true
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
let starship_config = toml::toml! {
|
|
|
|
[package]
|
|
|
|
display_private = true
|
|
|
|
};
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), Some(starship_config));
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-04-29 19:06:25 +00:00
|
|
|
#[test]
|
2021-08-06 19:16:14 +00:00
|
|
|
fn test_node_package_version_semantic_development_version() -> io::Result<()> {
|
2021-04-29 19:06:25 +00:00
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
|
|
|
"version": "0.0.0-development"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("semantic"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-06 19:16:14 +00:00
|
|
|
fn test_node_package_version_with_semantic_other_version() -> io::Result<()> {
|
2021-04-29 19:06:25 +00:00
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
|
|
|
"version": "v0.0.0-semantically-released"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("semantic"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-10-13 05:42:55 +00:00
|
|
|
#[test]
|
|
|
|
fn test_crystal_shard_version() -> io::Result<()> {
|
|
|
|
let config_name = "shard.yml";
|
|
|
|
let config_content = "name: starship\nversion: 1.2.3\n".to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
|
|
|
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-04-29 19:06:25 +00:00
|
|
|
#[test]
|
2021-08-06 19:16:14 +00:00
|
|
|
fn test_node_package_version_with_non_semantic_tag() -> io::Result<()> {
|
2021-04-29 19:06:25 +00:00
|
|
|
let config_name = "package.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
|
|
|
"version": "v0.0.0-alpha"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v0.0.0-alpha"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_poetry_version() -> io::Result<()> {
|
|
|
|
let config_name = "pyproject.toml";
|
|
|
|
let config_content = toml::toml! {
|
2019-08-15 20:41:06 +00:00
|
|
|
[tool.poetry]
|
|
|
|
name = "starship"
|
|
|
|
version = "0.1.0"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2019-08-15 20:41:06 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_poetry_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "pyproject.toml";
|
|
|
|
let config_content = toml::toml! {
|
2019-08-15 20:41:06 +00:00
|
|
|
[tool.poetry]
|
|
|
|
name = "starship"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2019-08-15 20:41:06 +00:00
|
|
|
}
|
2021-07-27 15:58:35 +00:00
|
|
|
|
2022-05-02 16:44:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_pep621_version() -> io::Result<()> {
|
|
|
|
let config_name = "pyproject.toml";
|
|
|
|
let config_content = toml::toml! {
|
|
|
|
[project]
|
|
|
|
name = "starship"
|
|
|
|
version = "0.1.0"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_pep621_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "pyproject.toml";
|
|
|
|
let config_content = toml::toml! {
|
|
|
|
[project]
|
|
|
|
name = "starship"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, None, None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_pep621_version_attr_directive() -> io::Result<()> {
|
|
|
|
let config_name = "pyproject.toml";
|
|
|
|
let config_content = toml::toml! {
|
|
|
|
[project]
|
|
|
|
name = "starship"
|
|
|
|
version = {attr = "starship.__version__"}
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, None, None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_pep621_version_file_directive() -> io::Result<()> {
|
|
|
|
let config_name = "pyproject.toml";
|
|
|
|
let config_content = toml::toml! {
|
|
|
|
[project]
|
|
|
|
name = "starship"
|
|
|
|
version = {file = "VERSION.txt"}
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, None, None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-07-27 15:58:35 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_setup_cfg_version() -> io::Result<()> {
|
|
|
|
let config_name = "setup.cfg";
|
|
|
|
let config_content = String::from(
|
|
|
|
"[metadata]
|
|
|
|
version = 0.1.0",
|
|
|
|
);
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_setup_cfg_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "setup.cfg";
|
|
|
|
let config_content = String::from("[metadata]");
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, None, None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
2021-09-14 17:17:05 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_setup_cfg_version_attr() -> io::Result<()> {
|
|
|
|
let config_name = "setup.cfg";
|
|
|
|
let config_content = String::from(
|
|
|
|
"[metadata]
|
|
|
|
version = attr: mymod.__version__",
|
|
|
|
);
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, None, None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_setup_cfg_version_file() -> io::Result<()> {
|
|
|
|
let config_name = "setup.cfg";
|
|
|
|
let config_content = String::from(
|
|
|
|
"[metadata]
|
|
|
|
version = file: version.txt",
|
|
|
|
);
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, None, None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
2019-12-12 02:05:39 +00:00
|
|
|
|
2020-02-21 19:12:21 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_gradle_version_single_quote() -> io::Result<()> {
|
|
|
|
let config_name = "build.gradle";
|
|
|
|
let config_content = "plugins {
|
2020-02-21 19:12:21 +00:00
|
|
|
id 'java'
|
|
|
|
id 'test.plugin' version '0.2.0'
|
|
|
|
}
|
|
|
|
version '0.1.0'
|
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
}";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-02-21 19:12:21 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_gradle_version_double_quote() -> io::Result<()> {
|
|
|
|
let config_name = "build.gradle";
|
|
|
|
let config_content = "plugins {
|
2020-02-21 19:12:21 +00:00
|
|
|
id 'java'
|
|
|
|
id 'test.plugin' version '0.2.0'
|
|
|
|
}
|
|
|
|
version \"0.1.0\"
|
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
}";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-02-21 19:12:21 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_gradle_version_rc_version() -> io::Result<()> {
|
|
|
|
let config_name = "build.gradle";
|
|
|
|
let config_content = "plugins {
|
2020-02-21 19:12:21 +00:00
|
|
|
id 'java'
|
|
|
|
id 'test.plugin' version '0.2.0'
|
|
|
|
}
|
|
|
|
version '0.1.0-rc1'
|
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
}";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0-rc1"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-02-21 19:12:21 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_gradle_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "build.gradle";
|
|
|
|
let config_content = "plugins {
|
2020-02-21 19:12:21 +00:00
|
|
|
id 'java'
|
|
|
|
id 'test.plugin' version '0.2.0'
|
|
|
|
}
|
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
}";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2020-02-21 19:12:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 16:39:54 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_mix_version() -> io::Result<()> {
|
|
|
|
let config_name = "mix.exs";
|
|
|
|
let config_content = "defmodule MyApp.MixProject do
|
2020-04-08 16:39:54 +00:00
|
|
|
use Mix.Project
|
|
|
|
|
|
|
|
def project do
|
|
|
|
[
|
|
|
|
app: :my_app,
|
|
|
|
version: \"1.2.3\",
|
|
|
|
elixir: \"~> 1.10\",
|
|
|
|
start_permanent: Mix.env() == :prod,
|
|
|
|
deps: deps()
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run \"mix help compile.app\" to learn about applications.
|
|
|
|
def application do
|
|
|
|
[extra_applications: [:logger]]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run \"mix help deps\" to learn about dependencies.
|
|
|
|
defp deps do
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-04-08 16:39:54 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_mix_version_partial_online() -> io::Result<()> {
|
|
|
|
let config_name = "mix.exs";
|
|
|
|
let config_content = " def project, do: [app: :my_app,version: \"3.2.1\"]";
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v3.2.1"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-04-08 16:39:54 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_mix_version_rc_version() -> io::Result<()> {
|
|
|
|
let config_name = "mix.exs";
|
|
|
|
let config_content = " def project do
|
2020-04-08 16:39:54 +00:00
|
|
|
[
|
|
|
|
app: :my_app,
|
|
|
|
version: \"1.0.0-alpha.3\"
|
|
|
|
]
|
|
|
|
end";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v1.0.0-alpha.3"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-04-08 16:39:54 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_mix_version_rc_with_build_version() -> io::Result<()> {
|
|
|
|
let config_name = "mix.exs";
|
|
|
|
let config_content = " def project do
|
2020-04-08 16:39:54 +00:00
|
|
|
[
|
|
|
|
app: :my_app,
|
|
|
|
version: \"0.9.9-dev+20130417140000.amd64\"
|
|
|
|
]
|
|
|
|
end";
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.9.9-dev+20130417140000.amd64"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2020-04-08 16:39:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 12:06:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_helm_chart_version() -> io::Result<()> {
|
|
|
|
let config_name = "Chart.yaml";
|
|
|
|
let config_content = "
|
|
|
|
apiVersion: v1
|
|
|
|
name: starship
|
|
|
|
version: 0.2.0
|
|
|
|
";
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.2.0"), None);
|
2020-07-29 12:06:47 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2019-12-12 02:05:39 +00:00
|
|
|
#[test]
|
2020-04-28 08:53:30 +00:00
|
|
|
fn test_extract_composer_version() -> io::Result<()> {
|
|
|
|
let config_name = "composer.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
2019-12-12 02:05:39 +00:00
|
|
|
"version": "0.1.0"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2019-12-12 02:05:39 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_composer_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "composer.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship"
|
2019-12-12 02:05:39 +00:00
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
2019-12-12 02:05:39 +00:00
|
|
|
}
|
2020-04-03 18:16:22 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-06 19:16:14 +00:00
|
|
|
fn test_extract_julia_project_version() -> io::Result<()> {
|
2020-04-28 08:53:30 +00:00
|
|
|
let config_name = "Project.toml";
|
|
|
|
let config_content = toml::toml! {
|
2020-04-03 18:16:22 +00:00
|
|
|
name = "starship"
|
|
|
|
version = "0.1.0"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
2020-04-03 18:16:22 +00:00
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
#[test]
|
2021-08-06 19:16:14 +00:00
|
|
|
fn test_extract_julia_project_version_without_version() -> io::Result<()> {
|
2020-04-28 08:53:30 +00:00
|
|
|
let config_name = "Project.toml";
|
|
|
|
let config_content = toml::toml! {
|
2020-04-03 18:16:22 +00:00
|
|
|
name = "starship"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-04-28 08:53:30 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:54:03 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_maven_version_with_deps() -> io::Result<()> {
|
|
|
|
// pom.xml with common nested tags and dependencies
|
|
|
|
let pom = "
|
|
|
|
<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
|
|
|
|
|
|
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>parent</artifactId>
|
|
|
|
<packaging>pom</packaging>
|
|
|
|
|
|
|
|
<version>0.3.20-SNAPSHOT</version>
|
|
|
|
|
|
|
|
<name>Test POM</name>
|
|
|
|
<description>Test POM</description>
|
|
|
|
|
|
|
|
<properties>
|
|
|
|
<jdk.version>1.8</jdk.version>
|
|
|
|
<jta.version>2.3.3</jta.version>
|
|
|
|
<woodstox.version>4.13</woodstox.version>
|
|
|
|
<jackson.version>3.3.3</jackson.version>
|
|
|
|
</properties>
|
|
|
|
|
|
|
|
<dependencyManagement>
|
|
|
|
<dependencies>
|
|
|
|
<dependency>
|
|
|
|
<groupId>jta</groupId>
|
|
|
|
<artifactId>jta</artifactId>
|
|
|
|
<version>${jta.version}</version>
|
|
|
|
</dependency>
|
|
|
|
<dependency>
|
|
|
|
<groupId>com.fasterxml.woodstox</groupId>
|
|
|
|
<artifactId>woodstox-core</artifactId>
|
|
|
|
<version>${woodstox.core.version}</version>
|
|
|
|
</dependency>
|
|
|
|
<dependency>
|
|
|
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
|
|
|
<artifactId>jackson-dataformat-xml</artifactId>
|
|
|
|
<version>${jackson.version}</version>
|
|
|
|
</dependency>
|
|
|
|
</dependencies>
|
|
|
|
</dependencyManagement>
|
|
|
|
|
|
|
|
<build>
|
|
|
|
<plugins>
|
|
|
|
<plugin>
|
|
|
|
<artifactId>maven-enforcer-plugin</artifactId>
|
|
|
|
<version>${maven.enforcer.version}</version>
|
|
|
|
<executions>
|
|
|
|
<execution>
|
|
|
|
<id>enforce-maven</id>
|
|
|
|
<goals>
|
|
|
|
<goal>enforce</goal>
|
|
|
|
</goals>
|
|
|
|
<configuration>
|
|
|
|
<rules>
|
|
|
|
<requireMavenVersion>
|
|
|
|
<version>3.0.5</version>
|
|
|
|
</requireMavenVersion>
|
|
|
|
</rules>
|
|
|
|
</configuration>
|
|
|
|
</execution>
|
|
|
|
</executions>
|
|
|
|
</plugin>
|
|
|
|
</plugins>
|
|
|
|
</build>
|
|
|
|
|
|
|
|
</project>";
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, "pom.xml", Some(pom))?;
|
2021-08-06 19:16:14 +00:00
|
|
|
expect_output(&project_dir, Some("v0.3.20-SNAPSHOT"), None);
|
2020-07-31 07:54:03 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_maven_version_no_version() -> io::Result<()> {
|
|
|
|
// pom.xml with common nested tags and dependencies
|
|
|
|
let pom = "
|
|
|
|
<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
|
|
|
|
|
|
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
|
|
|
|
<dependencies>
|
|
|
|
<dependency>
|
|
|
|
<groupId>jta</groupId>
|
|
|
|
<artifactId>jta</artifactId>
|
|
|
|
<version>1.2.3</version>
|
|
|
|
</dependency>
|
|
|
|
</dependencies>
|
|
|
|
|
|
|
|
</project>";
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, "pom.xml", Some(pom))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-07-31 07:54:03 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_maven_version_is_prop() -> io::Result<()> {
|
|
|
|
// pom.xml with common nested tags and dependencies
|
|
|
|
let pom = "
|
|
|
|
<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
|
|
|
|
|
|
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<version>${pom.parent.version}</version>
|
|
|
|
|
|
|
|
</project>";
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, "pom.xml", Some(pom))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-07-31 07:54:03 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_maven_version_no_version_but_deps() -> io::Result<()> {
|
|
|
|
// pom.xml with common nested tags and dependencies
|
|
|
|
let pom = "
|
|
|
|
<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
|
|
|
|
|
|
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>parent</artifactId>
|
|
|
|
<packaging>pom</packaging>
|
|
|
|
|
|
|
|
<name>Test POM</name>
|
|
|
|
<description>Test POM</description>
|
|
|
|
|
|
|
|
</project>";
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, "pom.xml", Some(pom))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-07-31 07:54:03 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2020-12-19 13:17:34 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_meson_version() -> io::Result<()> {
|
|
|
|
let config_name = "meson.build";
|
|
|
|
let config_content = "project('starship', 'rust', version: '0.1.0')".to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
2020-12-19 13:17:34 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_meson_version_without_version() -> io::Result<()> {
|
|
|
|
let config_name = "meson.build";
|
|
|
|
let config_content = "project('starship', 'rust')".to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
2021-02-11 20:08:17 +00:00
|
|
|
expect_output(&project_dir, None, None);
|
2020-12-19 13:17:34 +00:00
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:30:25 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_meson_version_with_meson_version() -> io::Result<()> {
|
|
|
|
let config_name = "meson.build";
|
|
|
|
let config_content =
|
|
|
|
"project('starship', 'rust', version: '0.1.0', meson_version: '>= 0.57.0')".to_string();
|
|
|
|
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-05-03 19:50:29 +00:00
|
|
|
#[test]
|
2021-05-07 14:22:18 +00:00
|
|
|
fn test_extract_vmod_version() -> io::Result<()> {
|
2021-05-03 19:50:29 +00:00
|
|
|
let config_name = "v.mod";
|
2021-05-07 14:22:18 +00:00
|
|
|
let config_content = "\
|
|
|
|
Module {
|
|
|
|
name: 'starship',
|
|
|
|
author: 'matchai',
|
|
|
|
version: '1.2.3'
|
|
|
|
}";
|
2021-05-03 19:50:29 +00:00
|
|
|
let project_dir = create_project_dir()?;
|
2021-07-29 18:27:46 +00:00
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
2021-05-03 19:50:29 +00:00
|
|
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-05-07 14:22:18 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_vpkg_version() -> io::Result<()> {
|
|
|
|
let config_name = "vpkg.json";
|
|
|
|
let config_content = json::json!({
|
|
|
|
"name": "starship",
|
|
|
|
"version": "0.1.0"
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(&config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v0.1.0"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2021-12-03 06:56:06 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_sbt_version() -> io::Result<()> {
|
|
|
|
let config_name = "build.sbt";
|
|
|
|
let config_content = "\
|
|
|
|
name := \"starship\"
|
|
|
|
version := \"1.2.3\"
|
|
|
|
scalaVersion := \"2.13.7\"
|
|
|
|
|
|
|
|
assembly / assemblyMergeStrategy := {
|
|
|
|
case PathList(\"META-INF\", _ @ _*) => MergeStrategy.discard
|
|
|
|
case _ => MergeStrategy.first
|
|
|
|
}
|
|
|
|
";
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extract_sbt_version_thisbuild() -> io::Result<()> {
|
|
|
|
let config_name = "build.sbt";
|
|
|
|
let config_content = "\
|
|
|
|
name := \"starship\"
|
|
|
|
ThisBuild / version := \"1.2.3\"
|
|
|
|
scalaVersion := \"2.13.7\"
|
|
|
|
";
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2022-05-26 14:42:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_daml_project_version() -> io::Result<()> {
|
|
|
|
let config_name = "daml.yaml";
|
|
|
|
let config_content = "
|
|
|
|
sdk-version: 2.2.0
|
|
|
|
version: 6.8.65
|
|
|
|
";
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v6.8.65"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:57:20 +00:00
|
|
|
#[test]
|
|
|
|
fn test_extract_dart_pub_version() -> io::Result<()> {
|
|
|
|
let config_name = "pubspec.yaml";
|
|
|
|
let config_content = "
|
|
|
|
name: starship
|
|
|
|
version: 1.0.0
|
|
|
|
|
|
|
|
environment:
|
|
|
|
sdk: '>=2.15.0 <3.0.0'
|
|
|
|
";
|
|
|
|
let project_dir = create_project_dir()?;
|
|
|
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
|
|
|
expect_output(&project_dir, Some("v1.0.0"), None);
|
|
|
|
project_dir.close()
|
|
|
|
}
|
|
|
|
|
2020-04-28 08:53:30 +00:00
|
|
|
fn create_project_dir() -> io::Result<TempDir> {
|
2021-01-20 18:34:18 +00:00
|
|
|
tempfile::tempdir()
|
2020-04-28 08:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fill_config(
|
|
|
|
project_dir: &TempDir,
|
|
|
|
file_name: &str,
|
|
|
|
contents: Option<&str>,
|
|
|
|
) -> io::Result<()> {
|
|
|
|
let mut file = File::create(project_dir.path().join(file_name))?;
|
|
|
|
file.write_all(contents.unwrap_or("").as_bytes())?;
|
|
|
|
file.sync_all()
|
|
|
|
}
|
|
|
|
|
2021-02-11 20:08:17 +00:00
|
|
|
fn expect_output(project_dir: &TempDir, contains: Option<&str>, config: Option<toml::Value>) {
|
2020-08-07 19:13:12 +00:00
|
|
|
let starship_config = config.unwrap_or(toml::toml! {
|
2020-04-28 08:53:30 +00:00
|
|
|
[package]
|
|
|
|
disabled = false
|
2020-08-07 19:13:12 +00:00
|
|
|
});
|
2020-04-28 08:53:30 +00:00
|
|
|
|
2020-08-07 19:13:12 +00:00
|
|
|
let actual = ModuleRenderer::new("package")
|
|
|
|
.path(project_dir.path())
|
|
|
|
.config(starship_config)
|
|
|
|
.collect();
|
2020-04-28 08:53:30 +00:00
|
|
|
let text = String::from(contains.unwrap_or(""));
|
|
|
|
let expected = Some(format!(
|
|
|
|
"is {} ",
|
|
|
|
Color::Fixed(208).bold().paint(format!("📦 {}", text))
|
|
|
|
));
|
|
|
|
|
|
|
|
if contains.is_some() {
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
} else {
|
|
|
|
assert_eq!(actual, None);
|
|
|
|
}
|
2020-04-03 18:16:22 +00:00
|
|
|
}
|
2019-05-01 14:45:56 +00:00
|
|
|
}
|