Skip to content

Commit

Permalink
"improved test structure"
Browse files Browse the repository at this point in the history
  • Loading branch information
Josee9988 committed Jul 8, 2021
1 parent 8cb8783 commit e911304
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 19 deletions.
21 changes: 15 additions & 6 deletions tests/TESTS_RUNNER.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#!/bin/bash

# ADD AS MANY LINES AS TESTS FILE YOU HAVE TO RUN THEM ALL
LGREEN='\033[0;32m'
NC='\033[0m' # No Color
TESTS_TRASH_DIR="tests/.ignore.tests_trash/"
declare -a files=("tests/project_scaffolding_test.sh" "tests/custom_data_test.sh") # all the tests

mkdir -p tests/.ignore.tests_trash
center() {
term_width="$(tput cols)"
padding="$(printf '%0.1s' +{1..500})"
echo -e "\n\n${LGREEN}$(printf '%*.*s %s %*.*s\n' 0 "$(((term_width - 2 - ${#1}) / 2))" "$padding" "$1" 0 "$(((term_width - 1 - ${#1}) / 2))" "$padding")${NC}\n"
}

echo -e "\n\n--------------------------------\nrunning ./tests/project_scaffolding.sh"
./tests/project_scaffolding.sh

#rm -r tests/.ignore.tests_trash
for file in "${files[@]}"; do
mkdir -p tests/.ignore.tests_trash
center "TEST: running test ./$file"
./"$file"
rm -r $TESTS_TRASH_DIR
done
28 changes: 15 additions & 13 deletions tests/project_scaffolding.sh → tests/custom_data_test.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
#! /bin/bash
# file: examples/arguments_test.sh
# file: examples/custom_data_test.sh

TESTS_TRASH_DIR="tests/.ignore.tests_trash"
USERNAME="FAKE_USERNAME_TESTS"
NAME="FAKE_NAME_TESTS"
MAIL="FAKE_EMAIL_TESTS"
OMIT_STR="--omit-commit-and-confirmation"

cp -r * $TESTS_TRASH_DIR --copy-content 2>/dev/null || :
cp -r .github/ $TESTS_TRASH_DIR --copy-contents
cp -r bin/ $TESTS_TRASH_DIR --copy-contents
cp .gitignore $TESTS_TRASH_DIR --copy-contents
rm -r $TESTS_TRASH_DIR/tests/ 2>/dev/null || :
rm -r $TESTS_TRASH_DIR/.git/ 2>/dev/null || :
oneTimeSetUp() {
cp -r * $TESTS_TRASH_DIR --copy-content 2>/dev/null || :
cp -r .github/ $TESTS_TRASH_DIR --copy-contents
cp -r bin/ $TESTS_TRASH_DIR --copy-contents
cp .gitignore $TESTS_TRASH_DIR --copy-contents
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
}

# TESTS
oneTimeTearDown() {
cd "../.." || exit
}

# TESTS
suite() {
cd $TESTS_TRASH_DIR || exit

bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $OMIT_STR

suite_addTest testDotGithubFolder
suite_addTest testDotGithubISSUE_TEMPLATE
suite_addTest testDotGithubISSUE_TEMPLATEFiles
suite_addTest testDotGithubFiles

}

testDotGithubFolder() {
Expand Down Expand Up @@ -63,4 +66,3 @@ testDotGithubFiles() {

# Load and run shUnit2.
. tests/shunit2
cd "../.." || exit
68 changes: 68 additions & 0 deletions tests/project_scaffolding_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#! /bin/bash
# file: examples/project_scaffolding_test.sh

TESTS_TRASH_DIR="tests/.ignore.tests_trash"
USERNAME="FAKE_USERNAME_TESTS"
NAME="FAKE_NAME_TESTS"
MAIL="FAKE_EMAIL_TESTS"
OMIT_STR="--omit-commit-and-confirmation"

oneTimeSetUp() {
cp -r * $TESTS_TRASH_DIR --copy-content 2>/dev/null || :
cp -r .github/ $TESTS_TRASH_DIR --copy-contents
cp -r bin/ $TESTS_TRASH_DIR --copy-contents
cp .gitignore $TESTS_TRASH_DIR --copy-contents
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
}

oneTimeTearDown() {
cd "../.." || exit
}

# TESTS
suite() {

suite_addTest testDotGithubFolder
suite_addTest testDotGithubISSUE_TEMPLATE
suite_addTest testDotGithubISSUE_TEMPLATEFiles
suite_addTest testDotGithubFiles
}

testDotGithubFolder() {
githubFolderFound=0
if [ -e ".github/" ]; then
githubFolderFound=1
fi
assertEquals 1 $githubFolderFound

}

testDotGithubISSUE_TEMPLATE() {
folderFound=0
if [ -e ".github/ISSUE_TEMPLATE" ]; then
folderFound=1
fi
assertEquals 1 $folderFound
}

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
}

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
}

# Load and run shUnit2.
. tests/shunit2

0 comments on commit e911304

Please sign in to comment.