From a1e089c211718e12cb611da643824a897f3c797d Mon Sep 17 00:00:00 2001 From: Nikhil Nair Date: Mon, 16 Aug 2021 04:26:03 +0530 Subject: [PATCH 1/3] addedlogs Signed-off-by: Nikhil Nair --- src/ign.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ign.cc b/src/ign.cc index 12ef07713..bfd7140df 100644 --- a/src/ign.cc +++ b/src/ign.cc @@ -36,6 +36,14 @@ char* g_argv[] = ////////////////////////////////////////////////// extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion() { + std::string home; + ignition::common::env(IGN_HOMEDIR, home); + + std::string recordPathMod = ignition::common::joinPaths(home, + ".ignition", "gazebo", "log",ignition::common::timeToIso(IGN_SYSTEM_TIME())); + ignLogInit(recordPathMod, "gui_console.log"); + + return strdup(IGNITION_GUI_VERSION_FULL); } From b9d8345e6418e01324614594e903a5d7f30d1e31 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Mon, 8 Nov 2021 14:53:53 -0800 Subject: [PATCH 2/3] Change directory to gui, move code to a new function, add test Signed-off-by: Louise Poubel --- src/ign.cc | 22 +++++++++++++++++----- src/ign_TEST.cc | 37 ++++++++++++++++++++++++++++++++++++- tutorials/02_commandline.md | 3 +++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/ign.cc b/src/ign.cc index bfd7140df..faba5dcc3 100644 --- a/src/ign.cc +++ b/src/ign.cc @@ -34,22 +34,28 @@ char* g_argv[] = }; ////////////////////////////////////////////////// -extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion() +void startConsoleLog() { std::string home; ignition::common::env(IGN_HOMEDIR, home); - std::string recordPathMod = ignition::common::joinPaths(home, - ".ignition", "gazebo", "log",ignition::common::timeToIso(IGN_SYSTEM_TIME())); - ignLogInit(recordPathMod, "gui_console.log"); - + std::string logPathMod = ignition::common::joinPaths(home, + ".ignition", "gui", "log", + ignition::common::timeToIso(IGN_SYSTEM_TIME())); + ignLogInit(logPathMod, "console.log"); +} +////////////////////////////////////////////////// +extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion() +{ return strdup(IGNITION_GUI_VERSION_FULL); } ////////////////////////////////////////////////// extern "C" IGNITION_GUI_VISIBLE void cmdPluginList() { + startConsoleLog(); + ignition::gui::Application app(g_argc, g_argv); auto pluginsList = app.PluginList(); @@ -73,6 +79,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdPluginList() ////////////////////////////////////////////////// extern "C" IGNITION_GUI_VISIBLE void cmdStandalone(const char *_filename) { + startConsoleLog(); + ignition::gui::Application app(g_argc, g_argv, ignition::gui::WindowType::kDialog); @@ -87,6 +95,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdStandalone(const char *_filename) ////////////////////////////////////////////////// extern "C" IGNITION_GUI_VISIBLE void cmdConfig(const char *_config) { + startConsoleLog(); + ignition::gui::Application app(g_argc, g_argv); if (!app.findChild()) @@ -111,6 +121,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdVerbose(const char *_verbosity) ////////////////////////////////////////////////// extern "C" IGNITION_GUI_VISIBLE void cmdEmptyWindow() { + startConsoleLog(); + ignition::gui::Application app(g_argc, g_argv); if (!app.findChild()) diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 80a240ac8..19f862d3f 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -21,6 +21,8 @@ #include +#include +#include #include #include "test_config.h" // NOLINT(build/include) @@ -52,10 +54,43 @@ std::string custom_exec_str(std::string _cmd) return result; } +using namespace ignition; + +class CmdLine : public ::testing::Test +{ + // Documentation inherited + protected: void SetUp() override + { + // Change environment variable so that test files aren't written to $HOME + common::env(IGN_HOMEDIR, this->realHome); + EXPECT_TRUE(common::setenv(IGN_HOMEDIR, this->kFakeHome.c_str())); + } + + // Documentation inherited + protected: void TearDown() override + { + // Restore $HOME + EXPECT_TRUE(common::setenv(IGN_HOMEDIR, this->realHome.c_str())); + } + + /// \brief Directory to act as $HOME for tests + public: const std::string kFakeHome = common::joinPaths(PROJECT_BINARY_PATH, + "test", "fake_home"); + + /// \brief Store user's real $HOME to set it back at the end of tests. + public: std::string realHome; +}; + // See https://github.com/ignitionrobotics/ign-gui/issues/75 -TEST(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list)) +TEST_F(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list)) { + EXPECT_TRUE(common::removeAll(this->kFakeHome)); + EXPECT_FALSE(common::exists(this->kFakeHome)); + std::string output = custom_exec_str("ign gui -l"); EXPECT_NE(output.find("TopicEcho"), std::string::npos) << output; EXPECT_NE(output.find("Publisher"), std::string::npos) << output; + + EXPECT_TRUE(common::exists(common::joinPaths(this->kFakeHome, ".ignition", + "gui"))); } diff --git a/tutorials/02_commandline.md b/tutorials/02_commandline.md index daa19ab4e..978021331 100644 --- a/tutorials/02_commandline.md +++ b/tutorials/02_commandline.md @@ -32,3 +32,6 @@ If you have Ignition Tools installed, you can use the `ign gui` command line too --force-version Use a specific library version. --versions Show the available versions. + +When using the command line tool, all console messages are logged to +`$HOME/.ignition/gui/log/`. From 6737a83f24916e64772d3e2f75af9b86c2d905fa Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Wed, 10 Nov 2021 21:47:04 -0800 Subject: [PATCH 3/3] Don't expect home to exist at test startup Signed-off-by: Louise Poubel --- src/ign_TEST.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 19f862d3f..cf3ba5ea7 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -84,7 +84,9 @@ class CmdLine : public ::testing::Test // See https://github.com/ignitionrobotics/ign-gui/issues/75 TEST_F(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list)) { - EXPECT_TRUE(common::removeAll(this->kFakeHome)); + // Clear home if it exists + common::removeAll(this->kFakeHome); + EXPECT_FALSE(common::exists(this->kFakeHome)); std::string output = custom_exec_str("ign gui -l");