gix-command-0.3.7/.cargo_vcs_info.json0000644000000001510000000000100132430ustar { "git": { "sha1": "4f98e94e0e8b79ed2899b35bef40f3c30b3025b0" }, "path_in_vcs": "gix-command" }gix-command-0.3.7/Cargo.toml0000644000000023520000000000100112460ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.65" name = "gix-command" version = "0.3.7" authors = ["Sebastian Thiel "] build = false include = [ "src/lib.rs", "LICENSE-*", ] autobins = false autoexamples = false autotests = false autobenches = false description = "A crate of the gitoxide project handling internal git command execution" readme = false license = "MIT OR Apache-2.0" repository = "https://github.com/Byron/gitoxide" [lib] name = "gix_command" path = "src/lib.rs" doctest = false [dependencies.bstr] version = "1.5.0" features = [ "std", "unicode", ] default-features = false [dependencies.gix-path] version = "^0.10.7" [dependencies.gix-trace] version = "^0.1.8" [dependencies.shell-words] version = "1.0" [dev-dependencies] gix-command-0.3.7/Cargo.toml.orig000064400000000000000000000012451046102023000147270ustar 00000000000000[package] name = "gix-command" version = "0.3.7" repository = "https://github.com/Byron/gitoxide" license = "MIT OR Apache-2.0" description = "A crate of the gitoxide project handling internal git command execution" authors = ["Sebastian Thiel "] edition = "2021" rust-version = "1.65" include = ["src/lib.rs", "LICENSE-*"] [lib] doctest = false [dependencies] gix-trace = { version = "^0.1.8", path = "../gix-trace" } gix-path = { version = "^0.10.7", path = "../gix-path" } bstr = { version = "1.5.0", default-features = false, features = ["std", "unicode"] } shell-words = "1.0" [dev-dependencies] gix-testtools = { path = "../tests/tools" } gix-command-0.3.7/LICENSE-APACHE000064400000000000000000000247461046102023000137770ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. gix-command-0.3.7/LICENSE-MIT000064400000000000000000000017771046102023000135060ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gix-command-0.3.7/src/lib.rs000064400000000000000000000450441046102023000137500ustar 00000000000000//! Launch commands very similarly to `Command`, but with `git` specific capabilities and adjustments. #![deny(rust_2018_idioms, missing_docs)] #![forbid(unsafe_code)] use std::io::Read; use std::{ ffi::OsString, path::{Path, PathBuf}, }; use bstr::{BString, ByteSlice}; /// A structure to keep settings to use when invoking a command via [`spawn()`][Prepare::spawn()], after creating it with [`prepare()`]. pub struct Prepare { /// The command to invoke (either with or without shell depending on `use_shell`. pub command: OsString, /// Additional information to be passed to the spawned command. pub context: Option, /// The way standard input is configured. pub stdin: std::process::Stdio, /// The way standard output is configured. pub stdout: std::process::Stdio, /// The way standard error is configured. pub stderr: std::process::Stdio, /// The arguments to pass to the spawned process. pub args: Vec, /// environment variables to set in the spawned process. pub env: Vec<(OsString, OsString)>, /// If `true`, we will use `sh` to execute the `command`. pub use_shell: bool, /// If `true` (default `true` on windows and `false` everywhere else) /// we will see if it's safe to manually invoke `command` after splitting /// its arguments as a shell would do. /// Note that outside of windows, it's generally not advisable as this /// removes support for literal shell scripts with shell-builtins. /// /// This mimics the behaviour we see with `git` on windows, which also /// won't invoke the shell there at all. /// /// Only effective if `use_shell` is `true` as well, as the shell will /// be used as a fallback if it's not possible to split arguments as /// the command-line contains 'scripting'. pub allow_manual_arg_splitting: bool, } /// Additional information that is relevant to spawned processes, which typically receive /// a wealth of contextual information when spawned from `git`. /// /// See [the git source code](https://github.com/git/git/blob/cfb8a6e9a93adbe81efca66e6110c9b4d2e57169/git.c#L191) /// for details. #[derive(Debug, Default, Clone)] pub struct Context { /// The `.git` directory that contains the repository. /// /// If set, it will be used to set the `GIT_DIR` environment variable. pub git_dir: Option, /// Set the `GIT_WORK_TREE` environment variable with the given path. pub worktree_dir: Option, /// If `true`, set `GIT_NO_REPLACE_OBJECTS` to `1`, which turns off object replacements, or `0` otherwise. /// If `None`, the variable won't be set. pub no_replace_objects: Option, /// Set the `GIT_NAMESPACE` variable with the given value, effectively namespacing all /// operations on references. pub ref_namespace: Option, /// If `true`, set `GIT_LITERAL_PATHSPECS` to `1`, which makes globs literal and prefixes as well, or `0` otherwise. /// If `None`, the variable won't be set. pub literal_pathspecs: Option, /// If `true`, set `GIT_GLOB_PATHSPECS` to `1`, which lets wildcards not match the `/` character, and equals the `:(glob)` prefix. /// If `false`, set `GIT_NOGLOB_PATHSPECS` to `1` which lets globs match only themselves. /// If `None`, the variable won't be set. pub glob_pathspecs: Option, /// If `true`, set `GIT_ICASE_PATHSPECS` to `1`, to let patterns match case-insensitively, or `0` otherwise. /// If `None`, the variable won't be set. pub icase_pathspecs: Option, /// If `true`, inherit `stderr` just like it's the default when spawning processes. /// If `false`, suppress all stderr output. /// If not `None`, this will override any value set with [`Prepare::stderr()`]. pub stderr: Option, } mod prepare { use std::borrow::Cow; use std::{ ffi::OsString, process::{Command, Stdio}, }; use bstr::ByteSlice; use crate::{extract_interpreter, win_path_lookup, Context, Prepare}; /// Builder impl Prepare { /// If called, the command will not be executed directly, but with `sh`, but only if the /// command passed to [`prepare`](super::prepare()) requires this. /// /// This also allows to pass shell scripts as command, or use commands that contain arguments which are subsequently /// parsed by `sh`. pub fn with_shell(mut self) -> Self { self.use_shell = self.command.to_str().map_or(true, |cmd| { cmd.as_bytes().find_byteset(b"|&;<>()$`\\\"' \t\n*?[#~=%").is_some() }); self } /// Unconditionally turn off using the shell when spawning the command. /// Note that not using the shell is the default so an effective use of this method /// is some time after [`with_shell()`][Prepare::with_shell()] was called. pub fn without_shell(mut self) -> Self { self.use_shell = false; self } /// Set additional `ctx` to be used when spawning the process. /// /// Note that this is a must for most kind of commands that `git` usually spawns, /// as at least they need to know the correct `git` repository to function. pub fn with_context(mut self, ctx: Context) -> Self { self.context = Some(ctx); self } /// Use a shell, but try to split arguments by hand if this can be safely done without a shell. /// /// If that's not the case, use a shell instead. pub fn with_shell_allow_argument_splitting(mut self) -> Self { self.allow_manual_arg_splitting = true; self.with_shell() } /// Configure the process to use `stdio` for _stdin. pub fn stdin(mut self, stdio: Stdio) -> Self { self.stdin = stdio; self } /// Configure the process to use `stdio` for _stdout_. pub fn stdout(mut self, stdio: Stdio) -> Self { self.stdout = stdio; self } /// Configure the process to use `stdio` for _stderr. pub fn stderr(mut self, stdio: Stdio) -> Self { self.stderr = stdio; self } /// Add `arg` to the list of arguments to call the command with. pub fn arg(mut self, arg: impl Into) -> Self { self.args.push(arg.into()); self } /// Add `args` to the list of arguments to call the command with. pub fn args(mut self, args: impl IntoIterator>) -> Self { self.args .append(&mut args.into_iter().map(Into::into).collect::>()); self } /// Add `key` with `value` to the environment of the spawned command. pub fn env(mut self, key: impl Into, value: impl Into) -> Self { self.env.push((key.into(), value.into())); self } } /// Finalization impl Prepare { /// Spawn the command as configured. pub fn spawn(self) -> std::io::Result { let mut cmd = Command::from(self); gix_trace::debug!(cmd = ?cmd); cmd.spawn() } } impl From for Command { fn from(mut prep: Prepare) -> Command { let mut cmd = if prep.use_shell { let split_args = prep .allow_manual_arg_splitting .then(|| { if gix_path::into_bstr(std::borrow::Cow::Borrowed(prep.command.as_ref())) .find_byteset(b"\\|&;<>()$`\n*?[#~%") .is_none() { prep.command .to_str() .and_then(|args| shell_words::split(args).ok().map(Vec::into_iter)) } else { None } }) .flatten(); match split_args { Some(mut args) => { let mut cmd = Command::new(args.next().expect("non-empty input")); cmd.args(args); cmd } None => { let mut cmd = Command::new(if cfg!(windows) { "sh" } else { "/bin/sh" }); cmd.arg("-c"); if !prep.args.is_empty() { if prep.command.to_str().map_or(true, |cmd| !cmd.contains("$@")) { prep.command.push(" \"$@\""); } else { gix_trace::debug!( "Will not add '$@' to '{:?}' as it seems to contain it already", prep.command ); } } cmd.arg(prep.command); cmd.arg("--"); cmd } } } else if cfg!(windows) { let program: Cow<'_, std::path::Path> = std::env::var_os("PATH") .and_then(|path| win_path_lookup(prep.command.as_ref(), &path)) .map(Cow::Owned) .unwrap_or(Cow::Borrowed(prep.command.as_ref())); if let Some(shebang) = extract_interpreter(program.as_ref()) { let mut cmd = Command::new(shebang.interpreter); // For relative paths, we may have picked up a file in the current repository // for which an attacker could control everything. Hence, strip options just like Git. // If the file was found in the PATH though, it should be trustworthy. if program.is_absolute() { cmd.args(shebang.args); } cmd.arg(prep.command); cmd } else { Command::new(prep.command) } } else { Command::new(prep.command) }; cmd.stdin(prep.stdin) .stdout(prep.stdout) .stderr(prep.stderr) .envs(prep.env) .args(prep.args); if let Some(ctx) = prep.context { if let Some(git_dir) = ctx.git_dir { cmd.env("GIT_DIR", &git_dir); } if let Some(worktree_dir) = ctx.worktree_dir { cmd.env("GIT_WORK_TREE", worktree_dir); } if let Some(value) = ctx.no_replace_objects { cmd.env("GIT_NO_REPLACE_OBJECTS", usize::from(value).to_string()); } if let Some(namespace) = ctx.ref_namespace { cmd.env("GIT_NAMESPACE", gix_path::from_bstring(namespace)); } if let Some(value) = ctx.literal_pathspecs { cmd.env("GIT_LITERAL_PATHSPECS", usize::from(value).to_string()); } if let Some(value) = ctx.glob_pathspecs { cmd.env( if value { "GIT_GLOB_PATHSPECS" } else { "GIT_NOGLOB_PATHSPECS" }, "1", ); } if let Some(value) = ctx.icase_pathspecs { cmd.env("GIT_ICASE_PATHSPECS", usize::from(value).to_string()); } if let Some(stderr) = ctx.stderr { cmd.stderr(if stderr { Stdio::inherit() } else { Stdio::null() }); } } cmd } } } fn is_exe(executable: &Path) -> bool { executable.extension() == Some(std::ffi::OsStr::new("exe")) } /// Try to find `command` in the `path_value` (the value of `PATH`) as separated by `;`, or return `None`. /// Has special handling for `.exe` extensions, as these will be appended automatically if needed. /// Note that just like Git, no lookup is performed if a slash or backslash is in `command`. fn win_path_lookup(command: &Path, path_value: &std::ffi::OsStr) -> Option { fn lookup(root: &bstr::BStr, command: &Path, is_exe: bool) -> Option { let mut path = gix_path::try_from_bstr(root).ok()?.join(command); if !is_exe { path.set_extension("exe"); } if path.is_file() { return Some(path); } if is_exe { return None; } path.set_extension(""); path.is_file().then_some(path) } if command.components().take(2).count() == 2 { return None; } let path = gix_path::os_str_into_bstr(path_value).ok()?; let is_exe = is_exe(command); for root in path.split(|b| *b == b';') { if let Some(executable) = lookup(root.as_bstr(), command, is_exe) { return Some(executable); } } None } /// Parse the shebang (`#!`) from the first line of `executable`, and return the shebang /// data when available. pub fn extract_interpreter(executable: &Path) -> Option { #[cfg(windows)] if is_exe(executable) { return None; } let mut buf = [0; 100]; // Note: just like Git let mut file = std::fs::File::open(executable).ok()?; let n = file.read(&mut buf).ok()?; shebang::parse(buf[..n].as_bstr()) } /// #[allow(clippy::empty_docs)] pub mod shebang { use bstr::{BStr, ByteSlice}; use std::ffi::OsString; use std::path::PathBuf; /// Parse `buf` to extract all shebang information. pub fn parse(buf: &BStr) -> Option { let mut line = buf.lines().next()?; line = line.strip_prefix(b"#!")?; let slash_idx = line.rfind_byteset(b"/\\")?; Some(match line[slash_idx..].find_byte(b' ') { Some(space_idx) => { let space = slash_idx + space_idx; Data { interpreter: gix_path::from_byte_slice(line[..space].trim()).to_owned(), args: line .get(space + 1..) .and_then(|mut r| { r = r.trim(); if r.is_empty() { return None; } match r.as_bstr().to_str() { Ok(args) => shell_words::split(args) .ok() .map(|args| args.into_iter().map(Into::into).collect()), Err(_) => Some(vec![gix_path::from_byte_slice(r).to_owned().into()]), } }) .unwrap_or_default(), } } None => Data { interpreter: gix_path::from_byte_slice(line.trim()).to_owned(), args: Vec::new(), }, }) } /// Shebang information as [parsed](parse()) from a buffer that should contain at least one line. /// /// ### Deviation /// /// According to the [shebang documentation](https://en.wikipedia.org/wiki/Shebang_(Unix)), it will only consider /// the path of the executable, along with the arguments as the consecutive portion after the space that separates /// them. Argument splitting would then have to be done elsewhere, probably in the kernel. /// /// To make that work without the kernel, we perform the splitting while Git just ignores options. /// For now it seems more compatible to not ignore options, but if it is important this could be changed. #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] pub struct Data { /// The interpreter to run. pub interpreter: PathBuf, /// The remainder of the line past the space after `interpreter`, without leading or trailing whitespace, /// as pre-split arguments just like a shell would do it. /// Note that we accept that illformed UTF-8 will prevent argument splitting. pub args: Vec, } } /// Prepare `cmd` for [spawning][std::process::Command::spawn()] by configuring it with various builder methods. /// /// Note that the default IO is configured for typical API usage, that is /// /// - `stdin` is null to prevent blocking unexpectedly on consumption of stdin /// - `stdout` is captured for consumption by the caller /// - `stderr` is inherited to allow the command to provide context to the user /// /// ### Warning /// /// When using this method, be sure that the invoked program doesn't rely on the current working dir and/or /// environment variables to know its context. If so, call instead [`Prepare::with_context()`] to provide /// additional information. pub fn prepare(cmd: impl Into) -> Prepare { Prepare { command: cmd.into(), context: None, stdin: std::process::Stdio::null(), stdout: std::process::Stdio::piped(), stderr: std::process::Stdio::inherit(), args: Vec::new(), env: Vec::new(), use_shell: false, allow_manual_arg_splitting: cfg!(windows), } } #[cfg(test)] mod tests { use super::*; #[test] fn internal_win_path_lookup() -> gix_testtools::Result { let root = gix_testtools::scripted_fixture_read_only("win_path_lookup.sh")?; let mut paths: Vec<_> = std::fs::read_dir(&root)? .filter_map(Result::ok) .map(|e| e.path().to_str().expect("no illformed UTF8").to_owned()) .collect(); paths.sort(); let lookup_path: OsString = paths.join(";").into(); assert_eq!( win_path_lookup("a/b".as_ref(), &lookup_path), None, "any path with separator is considered ready to use" ); assert_eq!( win_path_lookup("x".as_ref(), &lookup_path), Some(root.join("a").join("x.exe")), "exe will be preferred, and it searches left to right thus doesn't find c/x.exe" ); assert_eq!( win_path_lookup("x.exe".as_ref(), &lookup_path), Some(root.join("a").join("x.exe")), "no matter what, a/x won't be found as it's shadowed by an exe file" ); assert_eq!( win_path_lookup("exe".as_ref(), &lookup_path), Some(root.join("b").join("exe")), "it finds files further down the path as well" ); Ok(()) } }