Skip to content

Commit

Permalink
Review jp+pp
Browse files Browse the repository at this point in the history
  • Loading branch information
petrzpav committed Sep 19, 2023
1 parent 96b329d commit c83a0f2
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 135 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- New feature 'consolidate'.
- Function `check_x` to check and set executable flag.
- New function `get_artifacts_url` to generate links to logs.
- Update links with project ID during distribution in README files.
- User script support `{pre,post}-{collect,distribute}`.
- New variable `CHANGED_FILES` available for `evaluate` and `execute` scripts.
- New default execute file for Java `execute_java`.

### Changed

- Rename `badge_generate` function to `generate_badge`.
- Function `warning` simplified, returns zero status code.
- User script execution moved to a separate `function process_user_scripts`.
- Run IO tests and generate badges simplified and moved to a separate function `io_tests`.
- Run Java JUnit tests and generate badges simplified and moved to a separate function `java_junit_tests`.
- Run Java code style and generate badges simplified and moved to a separate function `java_code_style`.
- Execute file for shell `execute_shell` simplified.

### Removed

- Remove commands `academy collect` and `academy measure`.
- Function `check_lang` was removed.

## [0.5.2] - 2023-08-06

Expand Down
2 changes: 1 addition & 1 deletion commons
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ io_tests() {
&& link="$(get_artifact_url "${CI_PROJECT_ID}" "${CI_COMMIT_BRANCH}" "${IOTEST_LOG#"${WORKING_DIR}/"}" "${CI_JOB_NAME}")"
generate_badge 'IO Tests' "${passed}/${count}" "${test_color}" "${badge_name}" "${link}" "${title}"
}
java_juinit_tests() {
java_junit_tests() {
# defaults
declare -r badge_name='200-badge-java-junit'
declare -r JUNIT_LOG="${RESULTS}/junit.log"
Expand Down
15 changes: 9 additions & 6 deletions distribute
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,16 @@ distribute() {
&& exception 'Git status is not empty'
[[ -z "${CACHE_FOLDER}" ]] \
&& CACHE_FOLDER="$(mktemp -d)"
# shellcheck disable=SC1091
[[ "${COLLECT}" == 1 && -f "${DIR}/pre-distribute" ]] \
&& source "${DIR}/pre-distribute" "${CACHE_FOLDER}"
decalre action='distribute'
[[ "${COLLECT}" == 1 ]] \
&& action='collect'
# shellcheck disable=SC1090
[[ "${COLLECT}" == 1 && -f "${DIR}/pre-${action}" ]] \
&& source "${DIR}/pre-${action}" "${CACHE_FOLDER}"
process_users
# shellcheck disable=SC1091
[[ "${COLLECT}" == 1 && -f "${DIR}/post-distribute" ]] \
&& source "${DIR}/post-distribute" "${CACHE_FOLDER}"
# shellcheck disable=SC1090
[[ "${COLLECT}" == 1 && -f "${DIR}/post-${action}" ]] \
&& source "${DIR}/post-${action}" "${CACHE_FOLDER}"
return 0
}

Expand Down
4 changes: 2 additions & 2 deletions documentation/academy-evaluate.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Academy-Evaluate - evaluate project and create status badges

With each evaluate, a default `evaluate_${ACADEMY_LANG}` file is executed which can be overriden by a file of the same name in the .academy folder.

### `run_io_tests` function
### `io_tests` function

This function performs simple I/O tests. It accepts one parameter of a command run syntax.

For each folder from `iotest/*` the function defines a `FILE_PATH` variable e.g. `src/SumClass.java`. To use the variable, make sure it is not expanded, e.g. `run_io_tests "java \${FILE_PATH}"` or `run_io_tests ‘java ${FILE_PATH}’`.
For each folder from `iotest/*` the function defines a `FILE_PATH` variable e.g. `src/SumClass.java`. To use the variable, make sure it is not expanded, e.g. `io_tests "java \${FILE_PATH}"` or `io_tests ‘java ${FILE_PATH}’`.

For each `test_name.file_ext` in the folder, the function performs set of tests per `test_name` supporting the following extensions: `stdin`, `stdout`, `optarg` (not implemented), `sc`, `errout`.

Expand Down
11 changes: 11 additions & 0 deletions documentation/academy.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ evaluate
help
Display this usage.

## VARIABLES

DIR
Academy directory path.

WORKING_DIR
Wokrking directory path.

CHANGED_FILES
List of changed files. Available for `execute` and `evaluate` scripts.

## EXIT STATUS

1 Other error.
Expand Down
2 changes: 1 addition & 1 deletion evaluate_java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

io_tests "java \${FILE_PATH}"
java_juinit_tests
java_junit_tests
java_code_style
2 changes: 1 addition & 1 deletion evaluate_oracle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ spool on
spool off
exit
EOM
run_io_tests "sql -S ${ORACLE_LOGON} <<< \"${sql_cmd}\""
io_tests "sql -S ${ORACLE_LOGON} <<< \"${sql_cmd}\""
246 changes: 123 additions & 123 deletions iotest
Original file line number Diff line number Diff line change
@@ -1,138 +1,138 @@
#!/usr/bin/env bash

io_test_exit() {
printf -- '%s' "${1}" >&2
exit 1
}
is_long() {
[[ $(wc -l < "${1}") -gt 1 || $(head -1 "${1}" | wc -m) -gt 15 ]]
}
assert() {
declare input output expected status
input="${stdin}"
output="${1}"
expected="${2}"
if [[ -n "${stdin_file}" ]]; then
iotest_folder_path="$(dirname "${IOTEST_FOLDER}")"
is_long "${stdin_file}" \
&& printf -- "Input file: %s\n" "${stdin_file#"${iotest_folder_path}/"}" \
|| printf -- "Input: %s\n" "${input}"
fi
# shellcheck disable=SC2059
printf -- "${3}\n" "${output}"
# shellcheck disable=SC2059
printf -- "${4}\n" "${expected}"
printf -- 'Status: '
status=1
[[ "${output}" == "${expected}" ]] \
&& printf -- 'success' \
&& status=0 \
|| printf -- 'failed'
printf -- "\n"
return $status
}
assert_status() {
assert "${1}" "$(< "${2}")" 'Status code: %s' 'Expected status code: %s'
}
assert_stdout() {
assert "$(< "${1}")" "$(< "${2}")" 'Output: %s' 'Expected output: %s'
}
assert_stderr() {
assert "$(< "${1}")" "$(< "${2}")" 'Error output: %s' 'Expected error output: %s'
}
io_test() {
declare -r test_folder="${1}"
# shellcheck disable=SC2155
declare -r test_folder_name="$(basename "${test_folder}")"
declare -r test_name="${2}"
declare -r test_path="${test_folder}/${test_name}"
declare cmd="${IOTEST_CMD}"
echo "Test ${test_folder_name}/${test_name}"
# add loop variables
# shellcheck disable=SC2034
declare -r FILE_PATH="${WORKING_DIR}/${test_folder#"${IOTEST_FOLDER}/"}"
# TODO use optarg file
declare out_file err_file status_code stdin stdin_file
out_file="$(mktemp)"
err_file="$(mktemp)"
# run cmd once
if [[ -f "${test_path}.stdin" ]]; then
stdin="$(< "${test_path}.stdin")"
stdin_file="${test_path}.stdin"
eval "cat '${test_path}.stdin' | ${cmd} >'${out_file}' 2>'${err_file}'"
status_code=$?
else
stdin=''
stdin_file=''
eval "${cmd} >'${out_file}' 2>'${err_file}'"
status_code=$?
fi
declare retrun_code=0
# test status code
if [[ -f "${test_path}.sc" ]]; then
assert_status "${status_code}" "${test_path}.sc" \
|| retrun_code=1
fi
# test stdout
if [[ -f "${test_path}.stdout" ]]; then
assert_stdout "${out_file}" "${test_path}.stdout" \
|| retrun_code=1
fi
# test stderr
if [[ -f "${test_path}.stderr" ]]; then
echo "Stderr diff"
assert_stderr "${err_file}" "${test_path}.stderr" \
|| retrun_code=1
fi
[[ "${status_code}" == 0 ]] \
|| cat "${err_file}" >&2
rm "${out_file}"
rm "${err_file}"
return ${retrun_code}
}
run_io_tests() {
# run iotests
declare -i passed=0 count=0 local_passed local_count
# search deepest folders only by -links 2 (folder with 2 hardlinks)
if [[ -z "${IOTEST_SINGLE_NAME}" ]]; then
while read -r -d '' folder; do
local_passed=0
local_count=0
echo -e "%% file start ${folder#"${IOTEST_FOLDER}/"} %%"
main() {
io_test_exit() {
printf -- '%s' "${1}" >&2
exit 1
}
is_long() {
[[ $(wc -l < "${1}") -gt 1 || $(head -1 "${1}" | wc -m) -gt 15 ]]
}
assert() {
declare input output expected status
input="${stdin}"
output="${1}"
expected="${2}"
if [[ -n "${stdin_file}" ]]; then
iotest_folder_path="$(dirname "${IOTEST_FOLDER}")"
is_long "${stdin_file}" \
&& printf -- "Input file: %s\n" "${stdin_file#"${iotest_folder_path}/"}" \
|| printf -- "Input: %s\n" "${input}"
fi
# shellcheck disable=SC2059
printf -- "${3}\n" "${output}"
# shellcheck disable=SC2059
printf -- "${4}\n" "${expected}"
printf -- 'Status: '
status=1
[[ "${output}" == "${expected}" ]] \
&& printf -- 'success' \
&& status=0 \
|| printf -- 'failed'
printf -- "\n"
return $status
}
assert_status() {
assert "${1}" "$(< "${2}")" 'Status code: %s' 'Expected status code: %s'
}
assert_stdout() {
assert "$(< "${1}")" "$(< "${2}")" 'Output: %s' 'Expected output: %s'
}
assert_stderr() {
assert "$(< "${1}")" "$(< "${2}")" 'Error output: %s' 'Expected error output: %s'
}
io_test() {
declare -r test_folder="${1}"
# shellcheck disable=SC2155
declare -r test_folder_name="$(basename "${test_folder}")"
declare -r test_name="${2}"
declare -r test_path="${test_folder}/${test_name}"
declare cmd="${IOTEST_CMD}"
echo "Test ${test_folder_name}/${test_name}"
# add loop variables
# shellcheck disable=SC2034
declare -r FILE_PATH="${WORKING_DIR}/${test_folder#"${IOTEST_FOLDER}/"}"
# TODO use optarg file
declare out_file err_file status_code stdin stdin_file
out_file="$(mktemp)"
err_file="$(mktemp)"
# run cmd once
if [[ -f "${test_path}.stdin" ]]; then
stdin="$(< "${test_path}.stdin")"
stdin_file="${test_path}.stdin"
eval "cat '${test_path}.stdin' | ${cmd} >'${out_file}' 2>'${err_file}'"
status_code=$?
else
stdin=''
stdin_file=''
eval "${cmd} >'${out_file}' 2>'${err_file}'"
status_code=$?
fi
declare retrun_code=0
# test status code
if [[ -f "${test_path}.sc" ]]; then
assert_status "${status_code}" "${test_path}.sc" \
|| retrun_code=1
fi
# test stdout
if [[ -f "${test_path}.stdout" ]]; then
assert_stdout "${out_file}" "${test_path}.stdout" \
|| retrun_code=1
fi
# test stderr
if [[ -f "${test_path}.stderr" ]]; then
echo "Stderr diff"
assert_stderr "${err_file}" "${test_path}.stderr" \
|| retrun_code=1
fi
[[ "${status_code}" == 0 ]] \
|| cat "${err_file}" >&2
rm "${out_file}"
rm "${err_file}"
return ${retrun_code}
}
run() {
# run iotests
declare -i passed=0 count=0 local_passed local_count
# search deepest folders only by -links 2 (folder with 2 hardlinks)
if [[ -z "${IOTEST_SINGLE_NAME}" ]]; then
while read -r -d '' folder; do
local_passed=0
local_count=0
echo -e "%% file start ${folder#"${IOTEST_FOLDER}/"} %%"
# shellcheck disable=SC2012
for name in $(ls "${folder}/" | rev | cut -d. -f2- | rev | sort -u); do
count+=1
local_count+=1
# io_test "${folder}" "${name}" > /dev/null \
io_test "${folder}" "${name}" \
&& passed+=1 \
&& local_passed+=1
done
printf -- "%s IO tests: run %s, skipped 0, passed %s\n" "$(basename "${folder}")" \
"${local_count}" "${local_passed}"
echo -e "%% file end ${folder#"${IOTEST_FOLDER}/"} %%\n"
done < <(find "${IOTEST_FOLDER}" -type d -links 2 -print0)
else
declare -r folder="${IOTEST_FOLDER}/${IOTEST_SINGLE_NAME}"
count=1
# shellcheck disable=SC2012
for name in $(ls "${folder}/" | rev | cut -d. -f2- | rev | sort -u); do
count+=1
local_count+=1
# io_test "${folder}" "${name}" > /dev/null \
io_test "${folder}" "${name}" \
&& passed+=1 \
&& local_passed+=1
&& passed=1 \
|| passed=0
done
printf -- "%s IO tests: run %s, skipped 0, passed %s\n" "$(basename "${folder}")" \
"${local_count}" "${local_passed}"
echo -e "%% file end ${folder#"${IOTEST_FOLDER}/"} %%\n"
done < <(find "${IOTEST_FOLDER}" -type d -links 2 -print0)
else
declare -r folder="${IOTEST_FOLDER}/${IOTEST_SINGLE_NAME}"
count=1
# shellcheck disable=SC2012
for name in $(ls "${folder}/" | rev | cut -d. -f2- | rev | sort -u); do
io_test "${folder}" "${name}" \
&& passed=1 \
|| passed=0
done
fi
printf -- "Summary: run %s, skipped 0, passed %s\n" "${count}" "${passed}"
}
main() {
fi
printf -- "Summary: run %s, skipped 0, passed %s\n" "${count}" "${passed}"
}

[[ -n "${1}" ]] \
|| io_test_exit "Missing iotest folder"
[[ -n "${2}" ]] \
|| io_test_exit "Missing iotest cmd"
declare -r IOTEST_FOLDER="${1#"${WORKING_DIR}/"}"
declare -r IOTEST_CMD="${2}"
declare -r IOTEST_SINGLE_NAME="${3:-}"
run_io_tests
run
}

main "$@"

0 comments on commit c83a0f2

Please sign in to comment.