From f65b150049ec9dc5ff2500d7e54c464d530f2e66 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 4 Oct 2020 09:46:31 -0700 Subject: Display available extensions in the help text With recent changes we are able to execute user-provided extensions through the program. However, discoverability is arguably lacking, because nitrocli provides no insight into what extensions are available to begin with. This patch changes this state of affairs by listing available extensions in the help text. --- src/tests/extensions.rs | 30 ++++++++++++++++++++++++++++++ src/tests/run.rs | 6 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/extensions.rs b/src/tests/extensions.rs index a295949..d546e8a 100644 --- a/src/tests/extensions.rs +++ b/src/tests/extensions.rs @@ -8,6 +8,36 @@ use std::fs; use super::*; +#[test] +fn no_extensions_to_discover() -> anyhow::Result<()> { + let exts = crate::commands::discover_extensions(&ffi::OsString::new())?; + assert!(exts.is_empty(), "{:?}", exts); + Ok(()) +} + +#[test] +fn extension_discovery() -> anyhow::Result<()> { + let dir1 = tempfile::tempdir()?; + let dir2 = tempfile::tempdir()?; + + { + let ext1_path = dir1.path().join("nitrocli-ext1"); + let ext2_path = dir1.path().join("nitrocli-ext2"); + let ext3_path = dir2.path().join("nitrocli-super-1337-extensions111one"); + let _ext1 = fs::File::create(&ext1_path)?; + let _ext2 = fs::File::create(&ext2_path)?; + let _ext3 = fs::File::create(&ext3_path)?; + + let path = env::join_paths(&[dir1.path(), dir2.path()])?; + let mut exts = crate::commands::discover_extensions(&path)?; + // We can't assume a fixed ordering of extensions, because that is + // platform/file system dependent. So sort here to fix it. + exts.sort(); + assert_eq!(exts, vec!["ext1", "ext2", "super-1337-extensions111one"]); + } + Ok(()) +} + #[test] fn resolve_extensions() -> anyhow::Result<()> { let dir1 = tempfile::tempdir()?; diff --git a/src/tests/run.rs b/src/tests/run.rs index e4bbb28..1dae166 100644 --- a/src/tests/run.rs +++ b/src/tests/run.rs @@ -300,7 +300,11 @@ print("success") } let path = ext_dir.path().as_os_str().to_os_string(); - let out = Nitrocli::new().path(path).handle(&["ext"])?; + // Make sure that the extension appears in the help text. + let out = Nitrocli::new().path(&path).handle(&["--help"])?; + assert!(out.contains("ext Run the ext extension\n"), out); + // And, of course, that we can invoke it. + let out = Nitrocli::new().path(&path).handle(&["ext"])?; assert_eq!(out, "success\n"); Ok(()) } -- cgit v1.2.3