search_path.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2006, 2007 Julio M. Merino Vidal
  2. // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
  3. // Copyright (c) 2009 Boris Schaeling
  4. // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
  5. // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #define BOOST_TEST_MAIN
  10. #include <boost/test/included/unit_test.hpp>
  11. #include <boost/process/search_path.hpp>
  12. #include <boost/filesystem/path.hpp>
  13. #include <string>
  14. namespace bp = boost::process;
  15. namespace fs = boost::filesystem;
  16. BOOST_AUTO_TEST_CASE(search_path)
  17. {
  18. #if defined(BOOST_WINDOWS_API)
  19. std::string filename = "cmd";
  20. #elif defined(BOOST_POSIX_API)
  21. fs::path filename = "ls";
  22. #endif
  23. BOOST_CHECK(!bp::search_path(filename).empty());
  24. auto fs = bp::search_path(filename);
  25. std::cout << fs << std::endl;
  26. #if defined(BOOST_WINDOWS_API)
  27. std::vector<fs::path> path = {"C:\\Windows","C:\\Windows\\System32"};
  28. #elif defined(BOOST_POSIX_API)
  29. std::vector<fs::path> path = {"/usr/local/bin","/usr/bin","/bin"};
  30. #endif
  31. BOOST_CHECK(!bp::search_path(filename, path).empty());
  32. }