From 446e720840e677877a8e1d9f93abe32de685e692 Mon Sep 17 00:00:00 2001 From: Josee9988 Date: Thu, 8 Jul 2021 20:48:00 +0200 Subject: [PATCH] "refactored the code" --- tests/custom_data_test.sh | 102 ++++++++++++++++++++++-------- tests/project_scaffolding_test.sh | 30 +++++---- 2 files changed, 95 insertions(+), 37 deletions(-) diff --git a/tests/custom_data_test.sh b/tests/custom_data_test.sh index 393b993..b7e2edb 100755 --- a/tests/custom_data_test.sh +++ b/tests/custom_data_test.sh @@ -5,6 +5,7 @@ TESTS_TRASH_DIR="tests/.ignore.tests_trash" USERNAME="FAKE_USERNAME_TESTS" NAME="FAKE_NAME_TESTS" MAIL="FAKE_EMAIL_TESTS" +TYPE="FAKE_TYPE_TESTS" OMIT_STR="--omit-commit-and-confirmation" oneTimeSetUp() { @@ -15,7 +16,7 @@ oneTimeSetUp() { rm -r $TESTS_TRASH_DIR/tests/ 2>/dev/null || : rm -r $TESTS_TRASH_DIR/.git/ 2>/dev/null || : cd $TESTS_TRASH_DIR || exit - bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $OMIT_STR >/dev/null + bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $TYPE $OMIT_STR >/dev/null } oneTimeTearDown() { @@ -24,44 +25,95 @@ oneTimeTearDown() { # TESTS suite() { + suite_addTest testDotGithubISSUE_TEMPLATEAsignees + suite_addTest testDotGithubISSUE_TEMPLATEConfig + suite_addTest testDotGithubConfig + suite_addTest testDotGithubSecurity + suite_addTest testDotGithubCODEOWNERS + suite_addTest testDotGitignore + suite_addTest testDotChangelog +} + +testDotGithubISSUE_TEMPLATEAsignees() { + isTheAssigneeNotFound=0 + assigneesWithName="assignees: $USERNAME" + declare -a files=( + ".github/ISSUE_TEMPLATE/1-bug-report.md" ".github/ISSUE_TEMPLATE/2-failing-test.md" + ".github/ISSUE_TEMPLATE/3-docs-bug.md" ".github/ISSUE_TEMPLATE/4-feature-request.md" + ".github/ISSUE_TEMPLATE/5-enhancement-request.md" ".github/ISSUE_TEMPLATE/6-security-report.md" + ".github/ISSUE_TEMPLATE/7-question-support.md") - suite_addTest testDotGithubFolder - suite_addTest testDotGithubISSUE_TEMPLATE - suite_addTest testDotGithubISSUE_TEMPLATEFiles - suite_addTest testDotGithubFiles + for file in "${files[@]}"; do + if ! grep -q "$assigneesWithName" "$file"; then + isTheAssigneeNotFound=1 + fi + done + assertNotEquals 1 $isTheAssigneeNotFound } -testDotGithubFolder() { - githubFolderFound=0 - if [ -e ".github/" ]; then - githubFolderFound=1 +testDotGithubISSUE_TEMPLATEConfig() { + isTheAssigneeNotFound=0 + mailInConfig="url: mailto:$MAIL" + + if grep -q "$mailInConfig" ".github/ISSUE_TEMPLATE/config.yml"; then + isTheAssigneeNotFound=1 fi - assertEquals 1 $githubFolderFound + assertEquals 1 $isTheAssigneeNotFound +} +testDotGithubConfig() { + isNewIssueWelcomeCommentFound=0 + newIssueWelcomeComment="Thanks for opening your first issue in $USERNAME/$NAME! Be sure to" + + if grep -q "$newIssueWelcomeComment" ".github/config.yml"; then + isNewIssueWelcomeCommentFound=1 + fi + assertEquals 1 $isNewIssueWelcomeCommentFound } -testDotGithubISSUE_TEMPLATE() { - folderFound=0 - if [ -e ".github/ISSUE_TEMPLATE" ]; then - folderFound=1 +testDotGithubSecurity() { + isSecurityDataFound=0 + securityData1="(mailto:$MAIL)" + securityData2="[$MAIL]" + securityData3="he project's team and community take security issues" + + if grep -q "$securityData1" ".github/SECURITY.md" && grep -q "$securityData2" ".github/SECURITY.md" && grep -q "$securityData3" ".github/SECURITY.md"; then + isSecurityDataFound=1 fi - assertEquals 1 $folderFound + assertEquals 1 $isSecurityDataFound } -testDotGithubISSUE_TEMPLATEFiles() { - filesFound=0 - if [ -e ".github/ISSUE_TEMPLATE/1-bug-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/2-failing-test.md" ] && [ -e ".github/ISSUE_TEMPLATE/3-docs-bug.md" ] && [ -e ".github/ISSUE_TEMPLATE/4-feature-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/5-enhancement-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/6-security-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/7-question-support.md" ] && [ -e ".github/ISSUE_TEMPLATE/config.yml" ]; then - filesFound=1 +testDotGithubCODEOWNERS() { + isCodeownersDataFound=0 + usernameData="$USERNAME" + + if grep -q "$usernameData" ".github/CODEOWNERS"; then + isCodeownersDataFound=1 + fi + assertEquals 1 $isCodeownersDataFound +} + +testDotGitignore() { + isGitignoreDataFound=0 + gitignoreData1="###> $USERNAME/$NAME ###" + gitignoreData2="###< $USERNAME/$NAME ###" + + if grep -q "$gitignoreData1" ".gitignore" && grep -q "$gitignoreData2" ".gitignore"; then + isGitignoreDataFound=1 fi - assertEquals 1 $filesFound + assertEquals 1 $isGitignoreDataFound } -testDotGithubFiles() { - filesFound=0 - if [ -e ".github/CODEOWNERS" ] && [ -e ".github/CODE_OF_CONDUCT.md" ] && [ -e ".github/CONTRIBUTING.md" ] && [ -e ".github/ISSUE_TEMPLATE.md" ] && [ -e ".github/pull_request_template.md" ] && [ -e ".github/SECURITY.md" ] && [ -e ".github/SUPPORT.md" ] && [ -e ".github/issue_label_bot.yaml" ] && [ -e ".github/config.yml" ] && [ -e ".github/FUNDING.yml" ] && [ -e ".github/settings.yml" ]; then - filesFound=1 +testDotChangelog() { + isChangelogDataFound=0 + changelogData1="All notable changes to the" + changelogData2="**$NAME**" + changelogData3="$TYPE will be documented in this file." + + if grep -q "$changelogData1" "CHANGELOG.md" && grep -q "$changelogData2" "CHANGELOG.md" && grep -q "$changelogData3" "CHANGELOG.md"; then + isChangelogDataFound=1 fi - assertEquals 1 $filesFound + assertEquals 1 $isChangelogDataFound } # Load and run shUnit2. diff --git a/tests/project_scaffolding_test.sh b/tests/project_scaffolding_test.sh index 2e1526b..a338b9c 100755 --- a/tests/project_scaffolding_test.sh +++ b/tests/project_scaffolding_test.sh @@ -5,6 +5,7 @@ TESTS_TRASH_DIR="tests/.ignore.tests_trash" USERNAME="FAKE_USERNAME_TESTS" NAME="FAKE_NAME_TESTS" MAIL="FAKE_EMAIL_TESTS" +TYPE="FAKE_TYPE_TESTS" OMIT_STR="--omit-commit-and-confirmation" oneTimeSetUp() { @@ -15,7 +16,7 @@ oneTimeSetUp() { rm -r $TESTS_TRASH_DIR/tests/ 2>/dev/null || : rm -r $TESTS_TRASH_DIR/.git/ 2>/dev/null || : cd $TESTS_TRASH_DIR || exit - bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $OMIT_STR >/dev/null + bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $TYPE $OMIT_STR >/dev/null } oneTimeTearDown() { @@ -39,7 +40,6 @@ testDotGithubFolder() { githubFolderFound=1 fi assertEquals 1 $githubFolderFound - } testDotGithubISSUE_TEMPLATE() { @@ -51,19 +51,25 @@ testDotGithubISSUE_TEMPLATE() { } testDotGithubISSUE_TEMPLATEFiles() { - filesFound=0 - if [ -e ".github/ISSUE_TEMPLATE/1-bug-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/2-failing-test.md" ] && [ -e ".github/ISSUE_TEMPLATE/3-docs-bug.md" ] && [ -e ".github/ISSUE_TEMPLATE/4-feature-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/5-enhancement-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/6-security-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/7-question-support.md" ] && [ -e ".github/ISSUE_TEMPLATE/config.yml" ]; then - filesFound=1 - fi - assertEquals 1 $filesFound + declare -a files=( + ".github/ISSUE_TEMPLATE/1-bug-report.md" ".github/ISSUE_TEMPLATE/2-failing-test.md" + ".github/ISSUE_TEMPLATE/3-docs-bug.md" ".github/ISSUE_TEMPLATE/4-feature-request.md" + ".github/ISSUE_TEMPLATE/5-enhancement-request.md" ".github/ISSUE_TEMPLATE/6-security-report.md" + ".github/ISSUE_TEMPLATE/7-question-support.md") + + for file in "${files[@]}"; do + assertTrue " $file does not exist" "[ -e \"$file\" ]" + done } testDotGithubFiles() { - filesFound=0 - if [ -e ".github/CODEOWNERS" ] && [ -e ".github/CODE_OF_CONDUCT.md" ] && [ -e ".github/CONTRIBUTING.md" ] && [ -e ".github/ISSUE_TEMPLATE.md" ] && [ -e ".github/pull_request_template.md" ] && [ -e ".github/SECURITY.md" ] && [ -e ".github/SUPPORT.md" ] && [ -e ".github/issue_label_bot.yaml" ] && [ -e ".github/config.yml" ] && [ -e ".github/FUNDING.yml" ] && [ -e ".github/settings.yml" ]; then - filesFound=1 - fi - assertEquals 1 $filesFound + declare -a files=( + ".github/CODEOWNERS" ".github/CODE_OF_CONDUCT.md" ".github/CONTRIBUTING.md" ".github/ISSUE_TEMPLATE.md" + ".github/pull_request_template.md" ".github/SECURITY.md" ".github/SUPPORT.md" ".github/issue_label_bot.yaml" + ".github/config.yml" ".github/FUNDING.yml" ".github/settings.yml") + for file in "${files[@]}"; do + assertTrue " $file does not exist" "[ -e \"$file\" ]" + done } testTestRemovedFiles() {