diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89d9fb03eb..b664ae4588 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -108,6 +108,8 @@ Please add only the labels required to work on your feature, in order to avoid u F3D continuous integration will also check the coverage as it is a good way to evaluate if new features are being tested or not. When adding code to F3D, always try to cover it by adding/modifying [tests](doc/dev/06-TESTING.md). +Only if no coverage is possible, use `// LCOV_EXCL_START` and `// LCOV_EXCL_STOP` comments to exclude unreachable lines, +and add another comment to explain why it cannot be reached by the coverage CI. F3D continuous integration also checks formatting using clang-format and other tools and will inform you if changes needs to be made. Some [formatting rules](doc/dev/09-CODING_STYLE.md) are not enforced by clang-format and will be checked during the review process. diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index 0a0577c10c..76bc394f44 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -337,12 +337,13 @@ class F3DStarter::F3DInternals return F3DInternals::ParseStatefileContent( stream, {}, outOptions, outFiles, outFileGroups, outWindowSize); } + // LCOV_EXCL_START catch (const f3d::engine::statefile_exception& ex) { - // Unreachable in testing f3d::log::error(ex.what()); return false; } + // LCOV_EXCL_STOP } /* Add the app-specific `file_groups` entry (all file groups, including the ones not currently @@ -2259,7 +2260,8 @@ void F3DStarter::SaveStatefile(const std::string& filenameTemplate) std::optional file = f3d::utils::getEnv("CTEST_SAVE_STATEFILE_DIALOG_FILE"); if (!file.has_value()) { - // Unreachable in testing + // We cannot test dialogs in the CI + // LCOV_EXCL_START const char* pattern = "*.json"; char* ptr = tinyfd_saveFileDialog("Save Statefile", "f3d_state.json", 1, &pattern, "Statefiles"); @@ -2267,6 +2269,7 @@ void F3DStarter::SaveStatefile(const std::string& filenameTemplate) { file = ptr; } + // LCOV_EXCL_STOP } if (file.has_value() && !file.value().empty()) { @@ -2339,11 +2342,12 @@ void F3DStarter::SaveStatefileToClipboard() state.toClipboard(); f3d::log::info("Statefile copied to the clipboard"); } + // LCOV_EXCL_START catch (const f3d::engine::statefile_exception& ex) { - // Unreachable in testing f3d::log::error(ex.what()); } + // LCOV_EXCL_STOP } //---------------------------------------------------------------------------- @@ -2356,7 +2360,8 @@ void F3DStarter::LoadStatefile(const std::string& source) std::optional file = f3d::utils::getEnv("CTEST_LOAD_STATEFILE_DIALOG_FILE"); if (!file.has_value()) { - // Unreachable in testing + // We cannot test dialogs in the CI + // LCOV_EXCL_START const char* pattern = "*.json"; char* ptr = tinyfd_openFileDialog("Load Statefile", nullptr, 1, &pattern, "Statefiles", false); @@ -2364,6 +2369,7 @@ void F3DStarter::LoadStatefile(const std::string& source) { file = ptr; } + // LCOV_EXCL_STOP } if (file.has_value() && !file.value().empty()) { diff --git a/library/src/engine.cxx b/library/src/engine.cxx index 083394eab9..b528e3d757 100644 --- a/library/src/engine.cxx +++ b/library/src/engine.cxx @@ -396,15 +396,17 @@ engine::state engine::state::fromClipboard() { if (!clip::get_text(content)) { - // Unreachable in testing + // LCOV_EXCL_START throw engine::statefile_exception("Could not read a state from the clipboard"); + // LCOV_EXCL_STOP } } + // LCOV_EXCL_START catch (const clip::clip_exception& ex) { - // Unreachable in testing throw engine::statefile_exception(std::string("Could not use clip: ") + ex.what()); } + // LCOV_EXCL_STOP return engine::state::fromString(content); #else throw engine::statefile_exception( @@ -448,14 +450,16 @@ void engine::state::toClipboard() const { if (!clip::set_text(this->Content)) { - // Unreachable in testing + // LCOV_EXCL_START throw engine::statefile_exception("Could not copy the state to the clipboard"); + // LCOV_EXCL_STOP } } catch (const clip::clip_exception& ex) { - // Unreachable in testing + // LCOV_EXCL_START throw engine::statefile_exception(std::string("Could not use clip: ") + ex.what()); + // LCOV_EXCL_STOP } #else diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 91e86f60e3..7dc0d08b0b 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -1361,11 +1361,12 @@ interactor& interactor_impl::initCommands() f3d::engine::state::fromString(content).toClipboard(); log::info("Statefile copied to the clipboard"); } + // LCOV_EXCL_START catch (const f3d::engine::statefile_exception& ex) { - // Unreachable in testing log::error(ex.what()); } + // LCOV_EXCL_STOP }, command_documentation_t{ "save_statefile_to_clipboard", "save the current state into the system clipboard" }); @@ -1382,11 +1383,12 @@ interactor& interactor_impl::initCommands() this->Internals->Scene, this->Internals->Window, this->Internals->Options, st.toString()); log::info("Statefile loaded from the clipboard"); } + // LCOV_EXCL_START catch (const f3d::engine::statefile_exception& ex) { - // Unreachable in testing log::error(ex.what()); } + // LCOV_EXCL_STOP }, command_documentation_t{ "load_statefile_from_clipboard", "restore the state from the system clipboard" });