-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from mikaoelitiana/feat-homebrew-version
feat: create_install_command fn + tests
- Loading branch information
Showing
4 changed files
with
156 additions
and
8 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 |
---|---|---|
|
@@ -8,18 +8,29 @@ impl Homebrew { | |
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl PackageManager for Homebrew { | ||
fn install(&self, name: &str) -> Result<(), Error> { | ||
self.setup()?; | ||
let mut child = Command::new("sh") | ||
pub fn create_install_command(&self, name: &str) -> Command { | ||
let mut command = Command::new("sh"); | ||
command | ||
.arg("-c") | ||
.arg(format!("brew install {}", name)) | ||
.stdin(Stdio::inherit()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.spawn()?; | ||
.stderr(Stdio::inherit()); | ||
command | ||
} | ||
} | ||
|
||
impl Default for Homebrew { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl PackageManager for Homebrew { | ||
fn install(&self, name: &str) -> Result<(), Error> { | ||
self.setup()?; | ||
let mut child = self.create_install_command(name).spawn()?; | ||
child.wait()?; | ||
Ok(()) | ||
} | ||
|
@@ -56,3 +67,41 @@ impl PackageManager for Homebrew { | |
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_create_child_command_with_version() { | ||
let homebrew = Homebrew::new(); | ||
let command = homebrew.create_install_command("[email protected]"); | ||
assert_eq!(command.get_args().len(), 2); | ||
assert_eq!( | ||
command.get_args().last().unwrap().to_string_lossy(), | ||
"brew install [email protected]" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_create_child_command_without_version() { | ||
let homebrew = Homebrew::new(); | ||
let command = homebrew.create_install_command("neovim"); | ||
assert_eq!(command.get_args().len(), 2); | ||
assert_eq!( | ||
command.get_args().last().unwrap().to_string_lossy(), | ||
"brew install neovim" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_create_child_command_with_head() { | ||
let homebrew = Homebrew::new(); | ||
let command = homebrew.create_install_command("neovim --HEAD"); | ||
assert_eq!(command.get_args().len(), 2); | ||
assert_eq!( | ||
command.get_args().last().unwrap().to_string_lossy(), | ||
"brew install neovim --HEAD" | ||
); | ||
} | ||
} |
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
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,11 @@ | ||
{ | ||
"packages": ["rustup@latest", "libiconv@latest"], | ||
"shell": { | ||
"init_hook": ["rustup default stable", "cargo fetch"], | ||
"scripts": { | ||
"test": "cargo test -- --show-output", | ||
"start": "cargo run", | ||
"build-docs": "cargo doc" | ||
} | ||
} | ||
} |
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,82 @@ | ||
{ | ||
"lockfile_version": "1", | ||
"packages": { | ||
"libiconv@latest": { | ||
"last_modified": "2024-03-22T11:26:23Z", | ||
"resolved": "github:NixOS/nixpkgs/a3ed7406349a9335cb4c2a71369b697cecd9d351#libiconv", | ||
"source": "devbox-search", | ||
"version": "2.38", | ||
"systems": { | ||
"aarch64-linux": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/vzchfq6fvnvp6qipm393ymjbgxjjsysi-glibc-iconv-2.38", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/vzchfq6fvnvp6qipm393ymjbgxjjsysi-glibc-iconv-2.38" | ||
}, | ||
"x86_64-linux": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/qkg9zz9rpd6spva392vxl9i7i7yq98hn-glibc-iconv-2.38", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/qkg9zz9rpd6spva392vxl9i7i7yq98hn-glibc-iconv-2.38" | ||
} | ||
} | ||
}, | ||
"rustup@latest": { | ||
"last_modified": "2024-03-22T11:26:23Z", | ||
"plugin_version": "0.0.1", | ||
"resolved": "github:NixOS/nixpkgs/a3ed7406349a9335cb4c2a71369b697cecd9d351#rustup", | ||
"source": "devbox-search", | ||
"version": "1.26.0", | ||
"systems": { | ||
"aarch64-darwin": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/4h4wdqlcn4zjxkkyd6s97pg1xfajmd9v-rustup-1.26.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/4h4wdqlcn4zjxkkyd6s97pg1xfajmd9v-rustup-1.26.0" | ||
}, | ||
"aarch64-linux": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/aqjaj4clf99y11mpp9yhbp1c364gkx4h-rustup-1.26.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/aqjaj4clf99y11mpp9yhbp1c364gkx4h-rustup-1.26.0" | ||
}, | ||
"x86_64-darwin": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/wn6ka9g6nzgd1wfmyy5jfb9m89b9mzzc-rustup-1.26.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/wn6ka9g6nzgd1wfmyy5jfb9m89b9mzzc-rustup-1.26.0" | ||
}, | ||
"x86_64-linux": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/d2kbjhk0l81i1yflqfbkxqjfgq0xx1qz-rustup-1.26.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/d2kbjhk0l81i1yflqfbkxqjfgq0xx1qz-rustup-1.26.0" | ||
} | ||
} | ||
} | ||
} | ||
} |