Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
tests: do kdb check on all plugins
Browse files Browse the repository at this point in the history
fix inconsistent /empty, /module
document /module feature

LibAddMacro for generate_readme

warnings seem to work, as corrected in #12

add missing error symbol in success plugin
  • Loading branch information
Markus Raab committed Jul 11, 2014
1 parent 57159f6 commit aa46d4b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 57 deletions.
32 changes: 32 additions & 0 deletions cmake/Modules/LibAddMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,35 @@ function(my_add_static_module name)
add_library(${name} STATIC ${srcs})
endfunction()


#
# converts a README.md (markdown texts with key/value pairs)
# to a README.c that contains keys to be added in the contract
#
# the key/value pairs need to be written like:
# - infos/licence = BSD
#
# - infos/description =
# has a special functionality: when it is used the rest of the file
# is interpreted as description. So this key must be last.
#
function (generate_readme p)
# rerun cmake when README.md is changed
# also allows cmake variable substitution
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_BINARY_DIR}/README.out)

# read
FILE(READ ${CMAKE_CURRENT_BINARY_DIR}/README.out contents)
STRING(REGEX REPLACE "\\\\" "\\\\\\\\" contents "${contents}")
STRING(REGEX REPLACE "\"" "\\\\\"" contents "${contents}")
STRING(REGEX REPLACE "\n" "\\\\n\"\n\"" contents "${contents}")
STRING(REGEX REPLACE "- infos = ([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/licence *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/licence\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/author *= *([.@<>a-zA-Z0-9 %_-]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/author\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/provides *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/provides\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/placements *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/placements\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/recommends *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/recommends\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/needs *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/needs\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/description *= *(.*)\\\\n\"\n\"" "keyNew(\"system/elektra/modules/${p}/infos/description\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/README.c ${contents})
endfunction()
2 changes: 1 addition & 1 deletion src/libtools/src/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Modules::~Modules()
PluginPtr Modules::load(std::string const& pluginName)
{
KeySet config(1,
*Key( "system/empty",
*Key( "system/module",
KEY_VALUE, "this plugin was loaded without a config",
KEY_END),
KS_END);
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/doc/doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ int elektraDocOpen(Plugin *handle, Key *errorKey)
}
* @endcode
*
* If your plugin has no useful way to startup without config, the
* module loader would not be able to load the module, too.
* To solve that problem the module loader adds the configuration key
* /module. Even if your plugin is basically not able to startup
* successfully, it should still provide a fallback when /module
* is present, so that docGet() on system/elektra/modules can be
* called successfully later on.
*
* @note Make sure to free everything you allocate here within elektraDocClose().
*
* @return 0 on success
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/struct/struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ inline static int elektraStructOpenDelegator(ckdb::Plugin *handle, kdb::KeySet&
}
catch (const char* msg)
{
// TODO: warnings are not always passed when plugin
// creation failed?
ELEKTRA_ADD_WARNING (58, errorKey, msg);
return -1;
}
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/success/success.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ int elektraSuccessGet(Plugin *handle ELEKTRA_UNUSED, KeySet *returned, Key *pare
keyNew ("system/elektra/modules/success/exports/set",
KEY_FUNC, elektraSuccessSet,
KEY_END),
keyNew ("system/elektra/modules/success/exports/error",
KEY_FUNC, elektraSuccessError,
KEY_END),
keyNew ("system/elektra/modules/success/exports/checkfile",
KEY_FUNC, elektraSuccessCheckFile,
KEY_END),
Expand Down
24 changes: 0 additions & 24 deletions src/plugins/yajl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
find_package(Yajl REQUIRED)

#converts a README.md (markdown texts with key/value pairs)
#to a README.c that contains keys to be added in the contract
#
# Supports all
function (generate_readme p)
# hack to rerun cmake when README.md is changed:
# (but also allows cmake variable substitution as an upside
configure_file(README.md ${CMAKE_CURRENT_BINARY_DIR}/README.out)
FILE(READ ${CMAKE_CURRENT_BINARY_DIR}/README.out contents)
STRING(REGEX REPLACE "\\\\" "\\\\\\\\" contents "${contents}")
STRING(REGEX REPLACE "\"" "\\\\\"" contents "${contents}")
STRING(REGEX REPLACE "\n" "\\\\n\"\n\"" contents "${contents}")
STRING(REGEX REPLACE "- infos = ([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/licence *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/licence\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/author *= *([.@<>a-zA-Z0-9 %_-]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/author\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/provides *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/provides\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/placements *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/placements\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/recommends *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/recommends\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/needs *= *([a-zA-Z0-9 ]*)\\\\n\"" "keyNew(\"system/elektra/modules/${p}/infos/needs\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
STRING(REGEX REPLACE "\"- +infos/description *= *(.*)\\\\n\"\n\"" "keyNew(\"system/elektra/modules/${p}/infos/description\",\nKEY_VALUE, \"\\1\", KEY_END)," contents "${contents}")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/README.c ${contents})
endfunction()


if (YAJL_FOUND)
include (LibAddMacros)

Expand Down
28 changes: 0 additions & 28 deletions src/plugins/yajl/contract.h

This file was deleted.

35 changes: 33 additions & 2 deletions src/plugins/yajl/yajl_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,44 @@ static void elektraYajlParseSuppressEmpty(KeySet *returned, Key* parentKey)
}
}

static inline KeySet *elektraGetModuleConfig()
{
return ksNew (30,
keyNew ("system/elektra/modules/yajl",
KEY_VALUE, "yajl plugin waits for your orders", KEY_END),
keyNew ("system/elektra/modules/yajl/exports", KEY_END),
keyNew ("system/elektra/modules/yajl/exports/get",
KEY_FUNC, elektraYajlGet,
KEY_END),
keyNew ("system/elektra/modules/yajl/exports/set",
KEY_FUNC, elektraYajlSet,
KEY_END),
#include "README.c"
keyNew ("system/elektra/modules/yajl/infos/metadata",
KEY_END),
keyNew ("system/elektra/modules/yajl/infos/metadata/boolean",
KEY_VALUE,
"Used to signal that a value should be syntactically rendered as boolean\n"
"See system/elektra/modules/type/infos/metadata/boolean for information what a boolean is.",
KEY_END),
keyNew ("system/elektra/modules/yajl/infos/version",
KEY_VALUE, PLUGINVERSION, KEY_END),
keyNew ("system/elektra/modules/yajl/config", KEY_END),
keyNew ("system/elektra/modules/yajl/config/",
KEY_VALUE, "system",
KEY_END),
keyNew ("system/elektra/modules/yajl/config/below",
KEY_VALUE, "user",
KEY_END),
KS_END);
}

int elektraYajlGet(Plugin *handle ELEKTRA_UNUSED, KeySet *returned,
Key *parentKey)
{
if (!strcmp (keyName(parentKey), "system/elektra/modules/yajl"))
{
KeySet *moduleConfig =
#include "contract.h"
KeySet *moduleConfig = elektraGetModuleConfig();
ksAppend(returned, moduleConfig);
ksDel(moduleConfig);
return 1;
Expand Down
36 changes: 36 additions & 0 deletions tests/shell/check_kdb_internal_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@INCLUDE_COMMON@

echo
echo ELEKTRA KDB INTERNAL TEST SUITE
echo

check_version

FILE=`mktemp`
for PLUGIN in $PLUGINS
do
case "$PLUGIN" in
"template")
continue
;;
"doc")
continue
;;
"tracer")
continue
;;
"timeofday")
continue
;;
esac

> $FILE
$KDB check $PLUGIN 1> $FILE 2> $FILE
succeed_if "check of plugin $PLUGIN failed"

test ! -s $FILE
succeed_if "check of plugin $PLUGIN produced: \"`cat $FILE`\""
done
rm $FILE

end_script basic commands

0 comments on commit aa46d4b

Please sign in to comment.