diff --git a/build.sh b/build.sh index a36e4d4..824bee1 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,7 @@ #!/bin/bash # -# This file is part of Builder. +# Builder – Compile scripts for local installs of software packages. +# Copyright (C) 2020 Forschungszentrum Jülich GmbH, INM-6 # # Builder is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with Builder. If not, see . # +# SPDX-License-Identifier: GPL-3.0-or-later +# set -euo pipefail if [ -z "${BUILDER_PATH+x}" ]; then BUILDER_PATH="$(dirname "$(realpath "$0")")" diff --git a/build_functions.sh b/build_functions.sh index 5842a68..8f10fb3 100644 --- a/build_functions.sh +++ b/build_functions.sh @@ -1,5 +1,7 @@ +#!/bin/bash # -# This file is part of Builder. +# Builder – Compile scripts for local installs of software packages. +# Copyright (C) 2020 Forschungszentrum Jülich GmbH, INM-6 # # Builder is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with Builder. If not, see . # +# SPDX-License-Identifier: GPL-3.0-or-later +# ################################################################################ # Helper functions diff --git a/tests/license-header.bats b/tests/license-header.bats new file mode 100644 index 0000000..d7e70d5 --- /dev/null +++ b/tests/license-header.bats @@ -0,0 +1,72 @@ +#!/usr/bin/env bats +load test_helper + +test_planfiles_startwith() { + # This helper function searches for all files matching $2 pattern + # and complains about those not matching $1 regex. + FILESTART="$1" + NLINES="$(echo "$FILESTART" | wc -l)" + N_BAD=0 + for file in $(find "$BATS_TEST_DIRNAME/../plans" -type f -not -name "*.module" -not -name "*.txt" -not -name "*.sw*"); do + [ "$FILESTART" = "$(head -n $NLINES "$file")" ] || { + echo "$file does not contain correct copyright statement"; + echo "" + head -n $NLINES "$file" | diff -u /dev/stdin --label "$file" /dev/fd/9 --label "correct" 9<<<"$FILESTART" + echo "" + N_BAD=$(( $N_BAD + 1 )) + }; + done + [ $N_BAD -eq 0 ] || { + echo "$N_BAD BAD FILES" + false + } +} + +test_codefiles_startwith() { + # This helper function searches for all files matching $2 pattern + # and complains about those not matching $1 regex. + FILESTART="$1" + NLINES="$(echo "$FILESTART" | wc -l)" + N_BAD=0 + for file in $(find "$BATS_TEST_DIRNAME/.." -maxdepth 2 -type f -name "*.sh"); do + [ "$FILESTART" = "$(head -n $NLINES "$file")" ] || { + echo "$file does not contain correct copyright statement"; + echo "" + head -n $NLINES "$file" | diff -u /dev/stdin --label "$file" /dev/fd/9 --label "correct" 9<<<"$FILESTART" + echo "" + N_BAD=$(( $N_BAD + 1 )) + }; + done + [ $N_BAD -eq 0 ] || { + echo "$N_BAD BAD FILES" + false + } +} + +@test "check planfiles start with LICENSE header" { + run test_planfiles_startwith "$(<$BATS_TEST_DIRNAME/license-header.txt)" + if [ ${status} -ne 0 ]; then + cat <. +# +# SPDX-License-Identifier: GPL-3.0-or-later +# diff --git a/tests/planfiles.bats b/tests/planfiles.bats index e9db043..990fda7 100644 --- a/tests/planfiles.bats +++ b/tests/planfiles.bats @@ -19,27 +19,6 @@ test_files_contain() { } } -test_planfiles_startwith() { - # This helper function seaches for all files matching $2 pattern - # and complains about those not matching $1 regex. - FILESTART="$1" - NLINES="$(echo "$FILESTART" | wc -l)" - N_BAD=0 - for file in $(find "$BATS_TEST_DIRNAME/../plans" -type f -not -name "*.module" -not -name "*.txt" -not -name "*.sw*"); do - [ "$FILESTART" = "$(head -n $NLINES "$file")" ] || { - echo "$file does not contain correct copyright statement"; - echo "" - head -n $NLINES "$file" | diff -u /dev/stdin --label "$file" /dev/fd/9 --label "correct" 9<<<"$FILESTART" - echo "" - N_BAD=$(( $N_BAD + 1 )) - }; - done - [ $N_BAD -eq 0 ] || { - echo "$N_BAD BAD FILES" - false - } -} - @test "modules contain 'PREREQ_DEPENDS'" { run test_files_contain 'PREREQ_DEPENDS' "*.module" if [ ${status} -ne 0 ]; then @@ -110,38 +89,3 @@ EOT emit_debug_output && return 1 fi } - -@test "check planfiles start with LICENSE header" { - FILESTART="#!/bin/bash -# -# Builder – Compile scripts for local installs of software packages. -# Copyright (C) 2020 Forschungszentrum Jülich GmbH, INM-6 -# -# Builder is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Builder is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Builder. If not, see . -# -# SPDX-License-Identifier: GPL-3.0-or-later -#" - - run test_planfiles_startwith "$FILESTART" - if [ ${status} -ne 0 ]; then - cat <