1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <catch.hpp>
#include <facter/facts/collection.hpp>
#include <leatherman/execution/execution.hpp>
#include <leatherman/util/environment.hpp>
#include <boost/filesystem.hpp>
#include "../fixtures.hpp"
using namespace std;
using namespace facter::facts;
using namespace leatherman::execution;
using namespace leatherman::util;
using namespace boost::filesystem;
using namespace facter::testing;
SCENARIO("using libfacter from Java") {
collection_fixture facts;
facts.add_default_facts(true);
path jar_path = path(BINARY_DIRECTORY) / "lib" / "facter.jar";
string system_path;
environment::get("PATH", system_path);
CAPTURE(JAVA_EXECUTABLE);
CAPTURE(LIBFACTER_OUTPUT_DIRECTORY);
CAPTURE(jar_path);
GIVEN("the os fact") {
try {
auto exec = execute(
JAVA_EXECUTABLE,
{
"-jar",
jar_path.string(),
"os"
},
{
{ "FACTERDIR", LIBFACTER_OUTPUT_DIRECTORY },
{ "PATH", string(LIBFACTER_OUTPUT_DIRECTORY) + environment::get_path_separator() + system_path }
},
0,
{
execution_options::trim_output,
execution_options::merge_environment,
execution_options::throw_on_failure
});
CAPTURE(exec.output);
CAPTURE(exec.error);
THEN("the value should match") {
REQUIRE(exec.success);
ostringstream ss;
auto value = facts["os"];
REQUIRE(value);
value->write(ss);
REQUIRE(exec.output == ss.str());
}
} catch (child_exit_exception const& ex) {
CAPTURE(ex.output());
CAPTURE(ex.error());
CAPTURE(ex.status_code());
FAIL("exception from child process.");
} catch (child_signal_exception const& ex) {
CAPTURE(ex.output());
CAPTURE(ex.error());
CAPTURE(ex.signal());
FAIL("signal from child process.");
}
}
}
|