-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{env, fs::{self, Permissions}, os::unix::fs::PermissionsExt}; | ||
|
||
use crate::modules::formatter::BashFormatter; | ||
|
||
fn create_fake_binary(fmt: BashFormatter) { | ||
let body = if cfg!(unix) { | ||
"#!/usr/bin/env bash\nexit 0" | ||
} else { | ||
panic!("this test is not available for non-unix platforms") | ||
}; | ||
|
||
let name: String = fmt.as_cmd(); | ||
|
||
fs::write(&name, body).expect("Couldn't write fake script"); | ||
fs::set_permissions(&name, Permissions::from_mode(0o755)).expect("Couldn't set perms for fake script"); | ||
} | ||
|
||
#[test] | ||
fn all_exist() { | ||
let path = env::var("PATH").expect("Cannot get $PATH"); | ||
|
||
env::set_var("PATH", format!("{path}:./")); // temporary unset to ensure that shfmt exists in $PATH | ||
let fmts = BashFormatter::get_all(); | ||
for fmt in fmts { | ||
create_fake_binary(fmt); | ||
assert_eq!(fmt.is_available(), true); | ||
assert_eq!(BashFormatter::get_available().is_some(), true); | ||
fs::remove_file(fmt.as_cmd::<String>()).expect("Couldn't remove formatter's fake binary"); | ||
} | ||
|
||
env::set_var("PATH", &path); | ||
assert_eq!(env::var("PATH").expect("Cannot get $PATH"), path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod formatter; | ||
pub mod validity; |