Commit 32242599 authored by Vojtěch Horký's avatar Vojtěch Horký
Browse files

Tasks 13

parent cb2d17e0
......@@ -18,3 +18,9 @@ tasks-12:
script:
- ./bin/run_tests.sh tasks/12
tasks-13:
stage: tests
image: registry.gitlab.com/mffd3s/nswi177/student:latest
script:
- ./bin/run_tests.sh tasks/13
#!/usr/bin/env bats
#> task: 13/UPSTREAM.md
load "../../nswi177"
NSWI177_13_COURSES=( \
NAIL062 \
NDBI025 \
NDMI002 \
NDMI011 \
NJAZ070 \
NJAZ072 \
NJAZ074 \
NJAZ090 \
NJAZ091 \
NMAI054 \
NMAI057 \
NMAI058 \
NMAI059 \
NMAI069 \
NPRG030 \
NPRG031 \
NPRG045 \
NPRG062 \
NSWI120 \
NSWI141 \
NSWI170 \
NSWI177 \
NTIN060 \
NTIN061 \
NTIN071 \
NTVY014 \
NTVY015 \
NTVY016 \
NTVY017 \
)
prepare() {
mkdir "${NSWI177_TEMP}/13"
cp -R 13/* "${NSWI177_TEMP}/13"
cd "${NSWI177_TEMP}"
}
stat_modif() {
stat -c '%Y' "$1"
}
run_make() {
run timeout 1m make -C 13 "$@"
msg="Expecting make to terminate with success" assert_status 0
}
fail_if_not_generated() {
if ! [ -f "13/$1" ]; then
fail "$1 was not generated at all."
fi
}
assert_incremental_build() {
local to_be_changed_src="$1"
local -a to_be_modified
local -a to_be_unchanged
while [[ "${1}" != '--' ]]; do
to_be_modified+=("${1}")
shift
done
shift
while [[ $# -gt 0 ]]; do
if [[ "${1}" == '--' ]]; then
shift
break
fi
to_be_unchanged+=("${1}")
shift
done
local -A original_timestamps
# Do a clean build
run_make clean "$@"
run_make "$@"
local i
for i in "${to_be_modified[@]}" "${to_be_unchanged[@]}"; do
fail_if_not_generated "$i"
original_timestamps[$i]="$( stat_modif "13/$i" )"
done
# Wait a little bit and rebuild
sleep 2
run_make "$@"
# No file shall be changed
local ts
for i in "${to_be_modified[@]}" "${to_be_unchanged[@]}"; do
fail_if_not_generated "$i"
ts="$( stat_modif "13/$i" )"
if [ "$ts" -ne "${original_timestamps[$i]}" ]; then
(
echo "Executed make twice (without changing anything)."
echo "Expected that $i would not be rebuilt, but its timestamp changed."
) | fail
fi
done
# Change the input file (no need to wait now)
touch "13/$to_be_changed_src"
run_make "$@"
# Only the expected file shall be changed or not touched at all
for i in "${to_be_unchanged[@]}"; do
fail_if_not_generated "$i"
ts="$( stat_modif "13/$i" )"
if [ "$ts" -ne "${original_timestamps[$i]}" ]; then
(
echo "Executed make twice (changed $to_be_changed_src only)."
echo "Expected that $i would not be rebuilt, but its timestamp changed."
) | fail
fi
done
for i in "${to_be_modified[@]}"; do
fail_if_not_generated "$i"
ts="$( stat_modif "13/$i" )"
if [ "$ts" -eq "${original_timestamps[$to_be_changed_src]}" ]; then
(
echo "Executed make twice (changed $to_be_changed_src only)."
echo "Expected that $i would be rebuilt, but its timestamp remained the same."
) | fail
fi
done
}
@test "13/Makefile - Submitted (0)" {
fail_if_missing
}
@test "13/Makefile - Generated files not committed (-20)" {
skip_if_missing
if [ -d "13/public_html" ]; then
cd 13/public_html
assert_file_not_committed '[^.]*'
cd ../..
fi
}
@test "13/Makefile - Target for cleaning (10)" {
skip_if_missing
prepare
run_make
run_make clean
if [ -d "13/public_html" ]; then
launch find 13/public_html/ -type f -not -name '.gitkeep' -not -name '.gitignore'
msg="After make clean, public_html should be empty" assert_output_equals ""
fi
}
@test "13/Makefile - Base build for index.html (20)" {
skip_if_missing
prepare
run_make
assert_file_has_mime_type "13/public_html/index.html" "text/html"
}
@test "13/Makefile - Base build for COURSE.html (10)" {
skip_if_missing
prepare
run_make
for course in "${NSWI177_13_COURSES[@]}"; do
assert_file_has_mime_type "13/public_html/${course}.html" "text/html"
done
}
@test "13/Makefile - Base build for main.css (10)" {
skip_if_missing
prepare
run_make
assert_file_has_mime_type "13/public_html/main.css" "text/*"
}
@test "13/Makefile - Incremental build for template.html (10)" {
skip_if_missing
prepare
assert_incremental_build "template.html" \
"public_html/index.html" "public_html/NSWI177.html" "public_html/main.css" "public_html/NSWI170.html" \
-- main.css
}
@test "13/Makefile - Incremental build of index.html (5)" {
skip_if_missing
prepare
assert_incremental_build "src/index.md" \
"public_html/index.html" \
-- "public_html/NSWI177.html" "public_html/main.css" "public_html/NSWI170.html"
}
@test "13/Makefile - Incremental build of main.css (5)" {
skip_if_missing
prepare
assert_incremental_build "main.css" \
"public_html/main.css" \
-- "public_html/index.html" "public_html/NSWI177.html" "public_html/NSWI170.html"
}
@test "13/Makefile - Incremental build of course pages (10)" {
skip_if_missing
prepare
assert_incremental_build "src/NSWI177.md" \
"public_html/NSWI177.html" \
-- "public_html/index.html" "public_html/main.css" "public_html/NSWI170.html"
assert_incremental_build "src/NSWI170.md" \
"public_html/NSWI170.html" \
-- "public_html/index.html" "public_html/main.css" "public_html/NSWI177.html"
}
@test "13/Makefile - Rebuild on meta information change (10)" {
skip_if_missing
prepare
assert_incremental_build "src/NSWI177.meta" \
"public_html/NSWI170.html" "public_html/index.html" "public_html/NSWI177.html" -- \
"public_html/main.css"
assert_incremental_build "src/NSWI170.meta" \
"public_html/NSWI170.html" "public_html/index.html" "public_html/NSWI177.html" -- \
"public_html/main.css"
}
@test "13/Makefile - Rebuild after adding new course (10)" {
skip_if_missing
prepare
if [ -f "13/src/NSWI004.md" ]; then
skip "src/NSWI004.md already exists"
fi
if [ -f "13/src/NSWI004.meta" ]; then
skip "src/NSWI004.meta already exists"
fi
echo '{"code": "NSWI004", "title": "Operating Systems", "credits": 4}' >13/src/NSWI004.meta
echo 'The course provides information on the operating system architecture and the features of process management, memory management, device drivers, file systems, networking, security. All features are shown on contemporary operating systems, implementation of selected features is practiced while creating an educational operating system. Note for combined study programs: the course requires activity during semester.' >13/src/NSWI004.md
run_make COURSES="NSWI004 NSWI177"
assert_file_has_mime_type "13/public_html/index.html" "text/html"
assert_file_has_mime_type "13/public_html/NSWI004.html" "text/html"
assert_file_has_mime_type "13/public_html/NSWI177.html" "text/html"
assert_incremental_build "src/NSWI177.md" \
"public_html/NSWI177.html" \
-- "public_html/index.html" "public_html/NSWI004.html" \
-- COURSES="NSWI004 NSWI177"
}
@test "13/Makefile - Code smells - Shellcheck (-10)" {
skip_if_missing
find 13 -name '*.sh' -print0 | while read IFS= read -r -d $'\0' filename; do
script="$filename" assert_is_shellchecked error
done
}
......@@ -10,3 +10,4 @@
2022-04-19 2022-05-02 10/*.bats
2022-04-27 2022-05-13 11/*.bats
2022-05-03 2022-05-16 12/*.bats
2022-05-10 2022-05-23 13/*.bats
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment