Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: myTAP implementation of pgTAP runtests #50

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
121 changes: 13 additions & 108 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Installation script for MyTAP

SQLHOST='localhost';
Expand All @@ -9,6 +11,8 @@ NOTESTS=0
NOINSTALL=0
FILTER=0

ALL_TESTS=$(echo $(ls tests/*my | cut -d. -f1 | cut -d'-' -f3-))

while [[ "${#}" > 0 ]]; do
case ${1} in
-u|--user)
Expand Down Expand Up @@ -55,7 +59,7 @@ Options:
-S, --socket filename MySQL host
-t, --no-tests Don't run the test suite when the install is completed
-i, --no-install Don't perform the installation, i.e. just run the test suite
-f, --filter string Perform the action on one class of objects <matching|eq|moretap|todo|utils|charset|collation|column|constraint|engine|event|index|partition|privilege|role|routines|table|trigger|schemata|user|view>
-f, --filter string Perform the action on one class of objects <${ALL_TESTS//\ /|}>
EOF
exit 1
;;
Expand Down Expand Up @@ -128,6 +132,7 @@ if [[ ${NOINSTALL} -eq 0 ]]; then
mysql ${MYSQLOPTS} --execute 'source ./mytap-index.sql';
mysql ${MYSQLOPTS} --execute 'source ./mytap-partition.sql';
mysql ${MYSQLOPTS} --execute 'source ./mytap-privilege.sql';
mysql ${MYSQLOPTS} --execute 'source ./mytap-runtests.sql';

if [[ ${MYVER} -ge 506004 ]]; then
echo "Importing Version 5.6.4 patches";
Expand All @@ -152,115 +157,15 @@ if [[ ${NOTESTS} -eq 0 ]]; then
if [[ ${FILTER} != 0 ]]; then
echo "Running test suite with filter: ${FILTER}";
else
echo "Running Full test suite, this will take a couple of minutes to complete."
fi

sleep 2;

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "matching" ]]; then
echo "============= matching ============="
mysql ${MYSQLOPTS} --database tap --execute 'source tests/matching.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "eq" ]]; then
echo "============= eq ============="
mysql ${MYSQLOPTS} --database tap --execute 'source tests/eq.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "moretap" ]]; then
echo "============= moretap ============="
mysql ${MYSQLOPTS} --database tap --execute 'source tests/moretap.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "todotap" ]]; then
echo "============= todotap ============="
mysql ${MYSQLOPTS} --database tap --execute 'source tests/todotap.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "utils" ]]; then
echo "============= utils ============="
mysql ${MYSQLOPTS} --database tap --execute 'source tests/utils.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "charset" ]]; then
echo "============= character sets ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-charset.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "collation" ]]; then
echo "============= collations ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-collation.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "column" ]]; then
echo "============= columns ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-column.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "constraint" ]]; then
echo "============= constraints ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-constraint.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "engine" ]]; then
echo "============= engines ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-engine.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "event" ]]; then
echo "============= events ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-event.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "index" ]]; then
echo "============= indexes ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-index.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "partition" ]]; then
echo "============= partitions ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-partition.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "privilege" ]]; then
echo "============= privileges ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-privilege.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "role" ]]; then
echo "============= role ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-role.my'
echo "Running full test suite."
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "routines" ]]; then
echo "============= routines ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-routines.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "schemata" ]]; then
echo "============= schemas ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-schemata.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "table" ]]; then
echo "============= tables ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-table.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "trigger" ]]; then
echo "============= triggers ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-trigger.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "user" ]]; then
echo "============= users ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-user.my'
fi

if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "view" ]]; then
echo "============= views ============"
mysql ${MYSQLOPTS} --database tap --execute 'source tests/test-mytap-view.my'
fi
for t in ${ALL_TESTS}; do
if [[ ${FILTER} == 0 ]] || [[ ${FILTER} =~ "${t}" ]]; then
echo "============= ${t} ============="
mysql ${MYSQLOPTS} --database tap --execute "source tests/test-mytap-${t}.my"
fi
done

fi

Expand Down
101 changes: 101 additions & 0 deletions mytap-runtests.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
USE tap;

DELIMITER //

DROP PROCEDURE IF EXISTS _run_proc_by_prefix //
CREATE PROCEDURE _run_proc_by_prefix(db_ TEXT, prefix_ TEXT)
BEGIN
DECLARE no_more_proc_to_call BOOLEAN DEFAULT 0;
DECLARE proc_to_call TEXT;

DECLARE c CURSOR FOR
SELECT ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE
ROUTINE_TYPE = 'PROCEDURE'
AND ROUTINE_SCHEMA = db_
AND ROUTINE_NAME LIKE CONCAT(prefix_, '%')
ORDER BY ROUTINE_NAME;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_proc_to_call = 1;

OPEN c;
l: LOOP
FETCH c INTO proc_to_call;
IF no_more_proc_to_call = 1 THEN
LEAVE l;
END IF;

SET @call_sql = CONCAT('CALL ', db_, '.', proc_to_call, '()');
PREPARE call_sql FROM @call_sql;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to use "random" @ variables? Should we take care about potential conflicts (like rename this variable to @mytap__call_sql)?

EXECUTE call_sql;
DEALLOCATE PREPARE call_sql;
END LOOP;
CLOSE c;
END //


DROP PROCEDURE IF EXISTS _runtests //
CREATE PROCEDURE _runtests(db_ TEXT, random_seed INT UNSIGNED)
BEGIN
DECLARE no_more_test_to_call BOOLEAN DEFAULT 0;
DECLARE test_to_call TEXT;
DECLARE c CURSOR FOR
SELECT ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE
ROUTINE_TYPE = 'PROCEDURE'
AND ROUTINE_SCHEMA = db_
AND ROUTINE_NAME LIKE 'test%'
ORDER BY
IF(random_seed IS NULL, NULL, RAND(random_seed))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a slight chance that shuffled order will be same as alphabetical one, but I don't think that's problem.

, ROUTINE_NAME;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_test_to_call = 1;

IF random_seed IS NULL THEN
SELECT '# Running tests...';
ELSE
SELECT CONCAT('# Running tests in random order with seed ', random_seed, '...');
END IF;


CALL _run_proc_by_prefix(db_, 'startup');

OPEN c;
l: LOOP
FETCH c INTO test_to_call;
IF no_more_test_to_call = 1 THEN
LEAVE l;
END IF;

CALL _run_proc_by_prefix(db_, 'setup');
SET @call_sql = CONCAT('CALL ', db_, '.', test_to_call, '()');
PREPARE call_sql FROM @call_sql;
SELECT CONCAT("# ... ", test_to_call);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe for i.e. my_prove? I was unable to test it.

EXECUTE call_sql;
DEALLOCATE PREPARE call_sql;
CALL _run_proc_by_prefix(db_, 'teardown');
END LOOP;
CLOSE c;

CALL _run_proc_by_prefix(db_, 'shutdown');
END //

DROP PROCEDURE IF EXISTS runtests //
CREATE procedure runtests(db_ TEXT)
BEGIN
CALL _runtests(db_, NULL);
END //

DROP PROCEDURE IF EXISTS runtests_random //
CREATE PROCEDURE runtests_random(db_ TEXT)
BEGIN
CALL _runtests(db_, FLOOR(RAND() * POW(2, 32)));
END //

DROP PROCEDURE IF EXISTS runtests_random_with_seed //
CREATE PROCEDURE runtests_random_with_seed(db_ TEXT, random_seed INT UNSIGNED)
BEGIN
CALL _runtests(db_, random_seed);
END //

DELIMITER ;
File renamed without changes.
File renamed without changes.
File renamed without changes.