Skip to content

Commit

Permalink
Merge develop for release of v0.07
Browse files Browse the repository at this point in the history
  • Loading branch information
Helma van der Linden committed Jun 18, 2018
2 parents 00194bd + 6bd1975 commit 7990219
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 55 deletions.
9 changes: 9 additions & 0 deletions Changes
@@ -1,6 +1,15 @@
Revision history for MyTAP
==========================

0.07 2018-06-18
-------------------------
* col_has_unique_index, col_hasnt_unique_index added to test for
the existence or absence of a unique index.
* tests added for the new functions.
* syntax errors fixed in the tests for the has[nt]_function and
has[nt]_procedure functions.
* runtests.sh script now has a filter option.

0.06 2017-06-18
-------------------------
* has_table and hasnt_table moved to separate file
Expand Down
4 changes: 4 additions & 0 deletions docs/documentation.md
Expand Up @@ -371,6 +371,10 @@ This function tests if the column is part of a key, not a primary key.

`col_hasnt_index_key( database, table, column, description )` checks if this column is NOT part of a key.

`col_has_unique_index`( database, table, column, description )` checks if this column has a unique key other than the primary key.

`col_hasnt_unique_index`( database, table, column, description )` checks if this column doesn't have a unique key other than the primary key.

### `col_has_named_index( database, table, column, keyname, description )`

This function tests if the column is part of a key with a specific name.
Expand Down
114 changes: 113 additions & 1 deletion mytap-column.sql
Expand Up @@ -216,6 +216,118 @@ BEGIN
END //


/****************************************************************************/
-- _col_has_unique_index (schema, table, column )

DROP FUNCTION IF EXISTS _col_has_unique_index //
CREATE FUNCTION _col_has_unique_index ( dbname TEXT, tname TEXT, cname TEXT )
RETURNS BOOLEAN
BEGIN
DECLARE ret BOOLEAN;

SELECT true into ret
FROM information_schema.statistics as db
WHERE db.table_schema = dbname
AND db.table_name = tname
AND db.column_name = cname
AND db.index_name <> 'PRIMARY'
AND db.non_unique = 0
limit 1; /* only use the first entry */
RETURN coalesce(ret, false);
END //

-- col_has_unique_index ( schema, table, column, keyname )
DROP FUNCTION IF EXISTS col_has_unique_index //
CREATE FUNCTION col_has_unique_index ( dbname TEXT, tname TEXT, cname TEXT, description TEXT )
RETURNS TEXT
BEGIN
IF NOT _has_column( dbname, tname, cname ) THEN
RETURN fail(concat('Error ',
diag (concat(' Column ', quote_ident(dbname), '.', quote_ident(tname), '.', quote_ident(cname), ' does not exist' ))));
END IF;

IF description = '' THEN
SET description = concat('Column ',
quote_ident(tname), '.', quote_ident(cname), ' should have unique INDEX' );
END IF;

RETURN ok( _col_has_unique_index(dbname, tname, cname), description );
END //

-- col_hasnt_unique_index( schema, table, column, keyname )
DROP FUNCTION IF EXISTS col_hasnt_unique_index //
CREATE FUNCTION col_hasnt_unique_index ( dbname TEXT, tname TEXT, cname TEXT, description TEXT )
RETURNS TEXT
BEGIN
IF NOT _has_column( dbname, tname, cname ) THEN
RETURN fail(concat('Error ',
diag (concat(' Column ', quote_ident(dbname), '.', quote_ident(tname), '.', quote_ident(cname), ' does not exist' ))));
END IF;

IF description = '' THEN
SET description = concat('Column ',
quote_ident(tname), '.', quote_ident(cname), ' should not have unique INDEX');
END IF;

RETURN ok( NOT _col_has_unique_index(dbname, tname, cname ), description );
END //

/****************************************************************************/
-- _col_has_non_unique_index (schema, table, column )

DROP FUNCTION IF EXISTS _col_has_non_unique_index //
CREATE FUNCTION _col_has_non_unique_index ( dbname TEXT, tname TEXT, cname TEXT )
RETURNS BOOLEAN
BEGIN
DECLARE ret BOOLEAN;

SELECT true into ret
FROM information_schema.statistics as db
WHERE db.table_schema = dbname
AND db.table_name = tname
AND db.column_name = cname
AND db.index_name <> 'PRIMARY'
AND db.non_unique = 1
limit 1; /* only use the first entry */
RETURN coalesce(ret, false);
END //

-- col_has_non_unique_index ( schema, table, column, keyname )
DROP FUNCTION IF EXISTS col_has_non_unique_index //
CREATE FUNCTION col_has_non_unique_index ( dbname TEXT, tname TEXT, cname TEXT, description TEXT )
RETURNS TEXT
BEGIN
IF NOT _has_column( dbname, tname, cname ) THEN
RETURN fail(concat('Error ',
diag (concat(' Column ', quote_ident(dbname), '.', quote_ident(tname), '.', quote_ident(cname), ' does not exist' ))));
END IF;

IF description = '' THEN
SET description = concat('Column ',
quote_ident(tname), '.', quote_ident(cname), ' should have non unique INDEX' );
END IF;

RETURN ok( _col_has_non_unique_index(dbname, tname, cname), description );
END //

-- col_hasnt_non_unique_index( schema, table, column, keyname )
DROP FUNCTION IF EXISTS col_hasnt_non_unique_index //
CREATE FUNCTION col_hasnt_non_unique_index ( dbname TEXT, tname TEXT, cname TEXT, description TEXT )
RETURNS TEXT
BEGIN
IF NOT _has_column( dbname, tname, cname ) THEN
RETURN fail(concat('Error ',
diag (concat(' Column ', quote_ident(dbname), '.', quote_ident(tname), '.', quote_ident(cname), ' does not exist' ))));
END IF;

IF description = '' THEN
SET description = concat('Column ',
quote_ident(tname), '.', quote_ident(cname), ' should not have non unique INDEX');
END IF;

RETURN ok( NOT _col_has_non_unique_index(dbname, tname, cname), description );
END //

/****************************************************************************/
-- _col_has_named_index (schema, table, column )

Expand Down Expand Up @@ -525,4 +637,4 @@ END //

/****************************************************************************/

DELIMITER ;
DELIMITER ;
2 changes: 1 addition & 1 deletion mytap.sql
Expand Up @@ -30,7 +30,7 @@ DROP FUNCTION IF EXISTS mytap_version //
CREATE FUNCTION mytap_version()
RETURNS VARCHAR(10)
BEGIN
RETURN '0.06';
RETURN '0.07';
END //

DROP FUNCTION IF EXISTS mysql_version //
Expand Down
44 changes: 44 additions & 0 deletions runsandboxtests.sh
@@ -0,0 +1,44 @@
#!/bin/bash
#
# Run tests against the various sandboxed MySQL servers


USER=msandbox
PW=msandbox
HOST=127.0.0.1

PORT55=3306
PORT56=5636
PORT57=5718
PORT80=8001

MYSQLOPTS="-h $HOST -u $USER -p$PW"

# ==== MySQL 5.5

echo "============= updating tap in 5.5 ============="
mysql $MYSQLOPTS --port=$PORT55 --execute 'source ./mytap.sql'

myprove/bin/my_prove tests/* -h $HOST -P $PORT55 -u $USER -p $PW

# ==== MySQL 5.6

echo "============= updating tap in 5.6 ============="
mysql $MYSQLOPTS --port=$PORT56 --execute 'source ./mytap.sql'

myprove/bin/my_prove tests/* -h $HOST -P $PORT56 -u $USER -p $PW

# ==== MySQL 5.7

echo "============= updating tap in 5.7 ============="
mysql $MYSQLOPTS --port=$PORT57 --execute 'source ./mytap.sql'

myprove/bin/my_prove tests/* -h $HOST -P $PORT57 -u $USER -p $PW

# ==== MySQL 8.0

# echo "============= updating tap in 8.0 ============="
# mysql $MYSQLOPTS --port=$PORT80 --execute 'source ./mytap.sql'

# myprove/bin/my_prove tests/* -h $HOST -P $PORT80 -u $USER -p $PW

71 changes: 64 additions & 7 deletions runtests.sh
Expand Up @@ -2,31 +2,88 @@

# shell script to run all tap tests

USER=$1
PASSW=$2
if (( $# < 2 )); then
echo ""
echo "$0 username password [--filter hastap|matching|eq|moretap|todotap|utils|viewtap|coltap|routinestap|triggertap]"
echo ""
exit 0
fi

MYSLOPTS="-u $USER -p$PASSW --disable-pager --batch --raw --skip-column-names --unbuffered"
USER="$1"; shift
PASSW="$1"; shift

# find out if we want to filter to a specific set
FILTER="$@"

if [[ ${FILTER:0:8} = "--filter" ]]; then
# strip the --filter prefix
FILTER=${FILTER:8}

# reset to everything when the filter is empty
if [[ "$FILTER" == "" ]]; then
FILTER=0
fi
else
# no filtering
FILTER=0
fi

MYSLOPTS="-h 127.0.0.1 -u $USER -p$PASSW --disable-pager --batch --raw --skip-column-names --unbuffered"

echo "============= updating tap ============="
mysql $MYSLOPTS --execute 'source ./mytap.sql'

echo "============= hastap ============="
mysql $MYSLOPTS --database tap --execute 'source tests/hastap.my'
echo "============= matching ============="
mysql $MYSLOPTS --database tap --execute 'source tests/matching.my'
if [[ $FILTER != 0 ]]; then
echo "============= filtering ============="
echo "$FILTER"
fi

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

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

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

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

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

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

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

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

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

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

0 comments on commit 7990219

Please sign in to comment.