Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added modules, more documentation, added bsf function

- partialy added module test (doc)
- added function loadModule of bsf-module
- added rules for Testing
- fixed documentation errors

Signed-off-by: Andrwe Lord Weber <lord-weber-andrwe@andrwe.org>
  • Loading branch information...
commit 7c0181aa94521dbf0b97040edbfcdcc10d9b1960 1 parent e8842fc
Andrwe Lord Weber authored
View
38 bsf.sh
@@ -37,14 +37,41 @@
######################################################################
COREPATH="$(readlink -f $0)"
-BSFPATH="${COREPATH%/*}"
-CONFIGPATH="${BSFPATH}/bsf.config"
+CONFIGPATH="${HOME}/.bsfrc"
+LOADEDMODULES=()
+
+echo ${COREPATH}
+echo $@
+echo $0
+
+
+# load given module and all dependencies
+function loadModule()
+{
+ local module="${1}"
+ grep -xFf <(printf '%s\n' ${LOADEDMODULES[@]}) <<<${module} && return 0
+ source "${BSFPATH}/${module}.sh" && LOADEDMODULES+="${module}" || return $?
+ source "${BSFPATH}/doc/${module}.txt" || return $?
+ for depend in $(grep "^m:" <(printf '%s\n' ${DEPENDS[@]}))
+ do
+ loadModule ${depend//m:/} || return $?
+ done
+ checkDepends $(grep -v "^m:" <(printf '%s\n' ${DEPENDS[@]})) || return $?
+}
-while getopts ":h?" opt
+while getopts ":h?c:b:" opt
do
case "${opt}" in
+ "c")
+ source "${OPTARG}"
+ shift 2
+ ;;
+ "b")
+ COREPATH="${OPTARG}"
+ shift 2
+ ;;
"h"|"?")
- for module in "${BSFPATH}/"*
+ for module in "${BSFPATH}/"*.sh
do
echo $(basename ${module%.sh})
done
@@ -53,8 +80,9 @@ do
esac
done
+BSFPATH="${COREPATH%/*}"
for module in $@
do
- source "${BSFPATH}/${module}.sh"
+ loadModule "${module}" || echo "Couldn't load module ${module}." >&2
done
View
5 doc/example-doc.txt
@@ -1,12 +1,17 @@
# Dependencies (m: -> depends on other module)
DEPENDS=( "grep" "sed" "m:debug" )
+
# Description of module
DESC="Example of a module including documentation and example implementation."
+
# Global arguments of module
ARGS=( "argument1='description of argument1'" "argument2='description of argument2'" )
+
# Public function of module
FUNCTIONS=( "function1='description of function1'" "function2='description of function2'" )
+
# Arguments of function (element number equals number of function in $FUNCTIONS
FUNCARGS=( "function1arg1='description':function1arg2='description'" "function2arg1='description'" )
+
# Return codes and values of function (element number equals number of function in $FUNCTIONS, 'echo -e'-syntax is supported
RETURNS=( "0 - success\nn - error-code of failed program of function1" "0 - success\nn - error-code\nstring - resulting output" )
View
20 doc/main_policies.txt
@@ -6,10 +6,21 @@ __Documentation__
- All documentation is placed in <BSF-DIR>/doc/.
- The documentation of a module has to be <BSF-DIR>/doc/<modulename>.txt
- Following points have to be documented for each module:
- - list of functionalities provided by the module
+ - list of functionalities provided by the module
- list of "public" functions with short description, arguments and return-codes
- dependencies needed (external programs, other modules)
- arguments which can be provided on module load and its description
+- for an example of the notation see <BSF-DIR>/doc/example-doc.txt
+
+
+__Testing__
+
+- Each module has to have a script testing it.
+- Test scripts are placed in <BSF-DIR>/test/.
+- The test scripts are named test-<module>.sh.
+- Each test script has to implement the function startTest() which runs all functions necessary to test the module.
+- The return code of startTest() has to be 0 on success with empty output or >0 on failure with a descriptive error message.
+- for an example see <BSF-DIR>/test/test-example.txt
__Implementation Steps__
@@ -19,7 +30,8 @@ __Implementation Steps__
3. Check whether the functionalities can be implemented in the same module or should be seperated.
e.g.: the module debug shouldn't implement a function getWebsite
4. Analyse functionalities and write down how they could be implemented using spoken language
-5. Implement and document function by function
+5. Create a test script which is able to test functionality by functionality
+6. Implement and document function by function
__Coding Guidelines__
@@ -33,8 +45,8 @@ __Coding Guidelines__
a - is not a descriptive name
debuglevel - is descriptive but a bit long
dbglvl - is descriptive and short enough
-- global variables has to be upper case e.g. VARIABLE
-- local variables has to be lower case e.g. variable
+- global variables have to be upper case e.g. VARIABLE
+- local variables have to be lower case e.g. variable
- variables should be as limited as possible
if a variable is only needed in one function it should be defined in this function using 'local'
if 2 or more functions use the same variable but the value may be different they are 2 different variables and should be defined 'local'
View
33 doc/test.txt
@@ -0,0 +1,33 @@
+# Dependencies (m: -> depends on other module)
+DEPENDS=( 'modules to test' )
+
+# Description of module
+DESC="Module for testing all modules"
+
+# Global arguments of module
+ARGS=( )
+
+# Public function of module
+FUNCTIONS=( "runTest='runs all tests'" )
+
+# Arguments of function (element number equals number of function in $FUNCTIONS
+FUNCARGS=( "module='Module to be tested'" )
+
+# Return codes and values of function (element number equals number of function in $FUNCTIONS, 'echo -e'-syntax is supported
+RETURNS=( "0 - success\nn - error-code of failed program of function1" )
+
+###########################################
+# Some notes
+#
+# called: bsf.sh test <module>
+# return: return code of module test script
+# output: output of module test script
+# functions:
+# -runFunction() <module-function>
+# -checkDepends() <dependencies[@]>
+# +runTest() <module>
+#
+# - use loadModule()
+# - should call all public functions of the module (=$FUNCTIONS)
+# - has to know all arguments for each function call (=$FUNCARGS)
+#
View
10 test.sh
@@ -1,4 +1,8 @@
-source bsf.sh debug
+#!/bin/bash
+
+function checkDepends()
+
+function runFunction()
+
+function runTest()
-echo ${BSFPATH}
-echo $bla
Please sign in to comment.
Something went wrong with that request. Please try again.