--source include/not_embedded.inc

#
# Test based on mysql-test/suite/sys_vars/t/all_vars.test
# and adapted for the performance schema tables.
#
# This test verifies that *all* performance schema tables are tested
# by the perfschema test suite.
# In particular, every table there must be covered by:
# - a ddl_<table_name>.test file.
# - a dml_<table_name>.test file.
#

#
# we can diff in perl or in sql, as it's my_SQL_test suite, do it in sql
#

perl;
  use File::Basename;
  my $dirname=dirname($ENV{MYSQLTEST_FILE});
  my @all_tests=<$dirname/*.test>;
  open(F, '>', "$ENV{MYSQLTEST_VARDIR}/tmp/perfschema-all_tests.txt") or die;
  binmode F;
  print F join "\n", sort map { basename $_ } @all_tests;
EOF

--disable_warnings
drop table if exists t1;
drop table if exists t2;
--enable_warnings

create table t1 (test_name text);
create table t2 (test_name text);
--replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR>
eval load data infile "$MYSQLTEST_VARDIR/tmp/perfschema-all_tests.txt" into table t1;

insert into t2 select concat('ddl_', table_name, '.test') from information_schema.tables
  where table_schema='performance_schema';
insert into t2 select concat('dml_', table_name, '.test') from information_schema.tables
  where table_schema='performance_schema';

# Abbreviations used for naming test files:
update t2 set test_name= replace(test_name, "events_waits_summary_", "ews_");
update t2 set test_name= replace(test_name, "events_stages_summary_", "esgs_");
update t2 set test_name= replace(test_name, "events_statements_summary_", "esms_");
update t2 set test_name= replace(test_name, "file_summary_", "fs_");
update t2 set test_name= replace(test_name, "objects_summary_", "os_");
update t2 set test_name= replace(test_name, "table_io_waits_summary_", "tiws_");
update t2 set test_name= replace(test_name, "table_lock_waits_summary_", "tlws_");

# Debug
# select test_name as 'FOUND' from t1;
# select test_name as 'EXPECTED' from t2;

delete from t2 where t2.test_name in (select t1.test_name from t1);

# If this fails, the test listed in the output is missing from the test suite.
# The way to fix the failure is to implement the missing test, not silence this select.
select test_name as `MISSING DDL/DML TESTS` from t2;

drop table t1;
drop table t2;

--remove_file $MYSQLTEST_VARDIR/tmp/perfschema-all_tests.txt
