test(ocaml): test custom switch indicators (#2657)

This commit is contained in:
Dario Vladović 2021-05-03 21:48:58 +02:00 committed by GitHub
parent c60ddf76f6
commit dead06ba14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 1 deletions

View File

@ -174,7 +174,7 @@ mod tests {
File::create(dir.path().join("package.json"))?.sync_all()?;
fs::write(
dir.path().join("package.lock"),
"{\"dependencies\": {\"ocaml\": \"4.8.1000\"}}",
r#"{"dependencies": {"ocaml": "4.8.1000"}}"#,
)?;
let actual = ModuleRenderer::new("ocaml").path(dir.path()).collect();
let expected = Some(format!(
@ -356,6 +356,35 @@ mod tests {
dir.close()
}
#[test]
fn with_global_opam_switch_custom_indicator() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("any.ml"))?.sync_all()?;
let actual = ModuleRenderer::new("ocaml")
.config(toml::toml! {
[ocaml]
global_switch_indicator = "g/"
})
.cmd(
"opam switch show --safe",
Some(CommandOutput {
stdout: String::from("ocaml-base-compiler.4.10.0\n"),
stderr: String::default(),
}),
)
.path(dir.path())
.collect();
let expected = Some(format!(
"via {}",
Color::Yellow
.bold()
.paint("🐫 v4.10.0 (g/ocaml-base-compiler.4.10.0) ")
));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn with_local_opam_switch() -> io::Result<()> {
let dir = tempfile::tempdir()?;
@ -378,4 +407,31 @@ mod tests {
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn with_local_opam_switch_custom_indicator() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("any.ml"))?.sync_all()?;
let actual = ModuleRenderer::new("ocaml")
.config(toml::toml! {
[ocaml]
local_switch_indicator = "^"
})
.cmd(
"opam switch show --safe",
Some(CommandOutput {
stdout: String::from("/path/to/my-project\n"),
stderr: String::default(),
}),
)
.path(dir.path())
.collect();
let expected = Some(format!(
"via {}",
Color::Yellow.bold().paint("🐫 v4.10.0 (^my-project) ")
));
assert_eq!(expected, actual);
dir.close()
}
}