Skip to content

Commit

Permalink
Merge pull request #47 from terhorstd/license_headers
Browse files Browse the repository at this point in the history
Fix license headers in code files
  • Loading branch information
terhorstd authored Jan 24, 2022
2 parents 9206d9b + 5d051b6 commit 4424f15
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 58 deletions.
5 changes: 4 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with Builder. If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
set -euo pipefail
if [ -z "${BUILDER_PATH+x}" ]; then
BUILDER_PATH="$(dirname "$(realpath "$0")")"
Expand Down
6 changes: 5 additions & 1 deletion build_functions.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with Builder. If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

################################################################################
# Helper functions
Expand Down
72 changes: 72 additions & 0 deletions tests/license-header.bats
Original file line number Diff line number Diff line change
@@ -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 <<EOT
---------------------------------------------------------------------------
Planfiles that are part of builder should start with an appropriate copyright
header. Please open any planfile and copy the first 16 lines verbatim into any
new planfile.
---------------------------------------------------------------------------
EOT
emit_debug_output && return 1
fi
}

@test "check source code starts with LICENSE header" {
run test_codefiles_startwith "$(<$BATS_TEST_DIRNAME/license-header.txt)"
if [ ${status} -ne 0 ]; then
cat <<EOT
---------------------------------------------------------------------------
Source code that are part of builder should start with an appropriate copyright
header. Please make sure each file starts exactly (!) with the content of the
file "tests/license-header.txt"
---------------------------------------------------------------------------
EOT
emit_debug_output && return 1
fi
}
20 changes: 20 additions & 0 deletions tests/license-header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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 <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
56 changes: 0 additions & 56 deletions tests/planfiles.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#"

run test_planfiles_startwith "$FILESTART"
if [ ${status} -ne 0 ]; then
cat <<EOT
---------------------------------------------------------------------------
Planfiles that are part of builder should start with an appropriate copyright
header. Please open any planfile and copy the first 16 lines verbatim into any
new planfile.
---------------------------------------------------------------------------
EOT
emit_debug_output && return 1
fi
}

0 comments on commit 4424f15

Please sign in to comment.