From e9205125eacdae6d52a9093e1a0c7e0c13831551 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Oct 2017 12:55:07 -0300 Subject: [PATCH] Testing: add test to check the shipped config-files for correctness. --- src/modules/CMakeLists.txt | 5 +++ src/modules/test_conf.cpp | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/modules/test_conf.cpp diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 48cda5c72..d48ecd29f 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -1,5 +1,10 @@ include( CMakeColors ) +if( BUILD_TESTING ) + add_executable( test_conf test_conf.cpp ) + target_link_libraries( test_conf ${YAMLCPP_LIBRARY} ) +endif() + file( GLOB SUBDIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*" ) string( REPLACE " " ";" SKIP_LIST "${SKIP_MODULES}" ) foreach( SUBDIRECTORY ${SUBDIRECTORIES} ) diff --git a/src/modules/test_conf.cpp b/src/modules/test_conf.cpp new file mode 100644 index 000000000..d5ac7c6ce --- /dev/null +++ b/src/modules/test_conf.cpp @@ -0,0 +1,66 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +/** + * This is a test-application that just checks the YAML config-file + * shipped with each module for correctness -- well, for parseability. + */ + +#include +#include + +using std::cerr; + +int main(int argc, char** argv) +{ + if (argc != 2) + { + cerr << "Usage: test_conf \n"; + return 1; + } + + try + { + YAML::Node doc = YAML::LoadFile( argv[1] ); + + if ( doc.IsNull() ) + { + // Special case: empty config files are valid, + // but aren't a map. For the example configs, + // this is still an error. + cerr << "WARNING:" << argv[1] << '\n'; + cerr << "WARNING: empty YAML\n"; + return 1; + } + + if ( !doc.IsMap() ) + { + cerr << "WARNING:" << argv[1] << '\n'; + cerr << "WARNING: not-a-YAML-map\n"; + return 1; + } + } + catch ( YAML::Exception& e ) + { + cerr << "WARNING:" << argv[1] << '\n'; + cerr << "WARNING: YAML parser error " << e.what() << '\n'; + return 1; + } + + return 0; +}