Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
;;
--no-run)
SBU_NO_RUN="${SBU_YES}"
(( parsed_arguments++ ))
;;
-o=*|--output-file=*)
SBU_JUNIT_REPORTER_OUTPUT_FILE="${argument#*=}"
(( parsed_arguments++ ))
;;
-t=*|--test-pattern=*)
SBU_TEST_FUNCTION_PATTERN="${argument#*=}"
(( parsed_arguments++ ))
;;
-r=*|--reporters=*)
SBU_REPORTERS="${argument#*=}"
(( parsed_arguments++ ))
;;
-*|--*)
_main__print_illegal_option "${argument}"
_main__print_usage_and_exit_with_code ${SBU_FAILURE_STATUS_CODE}
;;
esac
done
}
_main__assert_reporters_are_known() {
reporter__for_each_reporter _main__fail_if_reporter_unknown
}
_main__fail_if_reporter_unknown() {
if ! array__contains "${reporter}" "simple" "dots" "junit"; then
system__print_line \
"$(_main__get_script_name): unknown reporter <${reporter}>"
exit ${SBU_FAILURE_STATUS_CODE}
fi
}
_main__print_illegal_option() {
local option="${1%=*}"
option="${option#-}"
option="${option#-}"
system__print_line "$(_main__get_script_name): illegal option -- ${option}"
}
_main__assert_only_one_argument_left() {
if (( $1 > 1 )); then
system__print_line "$(_main__get_script_name): only one path is allowed"
_main__print_usage_and_exit_with_code ${SBU_FAILURE_STATUS_CODE}
fi
}
_main__get_script_name() {
basename "${BASH_SOURCE[0]}"
}
_main__print_usage_and_exit_with_code() {
_main__print_usage
exit $1
}
_main__print_full_usage() {
_main__print_usage
local script="$(_main__get_script_name)"
system__print_new_line
system__print_line "\
[options]
-a, --api-cheat-sheet
print api cheat sheet like assertions
-c, --colors=${SBU_YES} or ${SBU_NO}
tests output with colors or no
-d, --random-run=${SBU_YES} or ${SBU_NO}
tests files and functions randomly run or no
-f, --file-pattern=<pattern>
pattern to filter test files
-h
print usage
-o, --output-file=<file>
output file for JUnit reporter
-r, --reporters=<reporter1,reporter2>
comma-separated reporters (simple, dots or junit)
-t, --test-pattern=<pattern>
pattern to filter test function in files
[examples]
${script} .
run all tests in current directory
${script} -p=*test.sh sources/test
run all tests files ending with test.sh in sources/test"
}
_main__print_usage() {
system__print_line "\
usage: $(_main__get_script_name) [options] path
run all tests in path"
}
_main__print_api_cheat_sheet_and_exit() {
system__print_line "\
[assertions]
assertion__equal (value, other)
-> assert that <value> is equal to <other>
assertion__different (value, other)
-> assert that <value> is different from <other>
assertion__string_contains (string, substring)
-> assert that <string> contains <substring>
assertion__string_does_not_contain (string, substring)
-> assert that <string> does not contain <substring>
assertion__string_empty (string)
-> assert that <string> is empty
assertion__string_not_empty (string)
-> assert that <string> is not empty
assertion__array_contains (element, array[0], array[1], ...)
-> assert that the <array> contains the <element>
assertion__array_does_not_contain (element, array elements...)
-> assert that the <array> does not contain the <element>
assertion__successful (command)
-> assert that the <command> is successful
assertion__failing (command)
-> assert that the <command> is failing
assertion__status_code_is_success (code)
-> assert that the status <code> is 0
assertion__status_code_is_failure (code)
-> assert that the status <code> is not 0
[special functions]
${SBU_GLOBAL_SETUP_FUNCTION_NAME}
-> Executed before all tests in a file
${SBU_GLOBAL_TEARDOWN_FUNCTION_NAME}
-> Executed after all tests in a file
${SBU_SETUP_FUNCTION_NAME}
-> Executed before each test in a file
${SBU_TEARDOWN_FUNCTION_NAME}
-> Executed after each test in a file
[mocks]
mock__make_function_do_nothing (function_to_mock)
-> make function do nothing
mock__make_function_prints (function_to_mock, message)
-> make function prints a message
mock__make_function_call (function_to_mock, function_to_call)
-> make function call another function"
exit ${SBU_SUCCESS_STATUS_CODE}
}
main__main "$@"