Test::mysqld + perl -d ã使ã㨠SQLããã®ã¾ã¾å©ãã¦ä¾¿å©
id:zigorou å
çã«æãã¦ããã£ãæãã¡ã¢ã
(ãã¨ã§èª¿ã¹ã¦ã¿ãã http://perl-users.jp/articles/advent-calendar/2010/hacker/1 ã§ãã§ã«è¨åããã¦ãã¾ããããSQLå©ããã¨ããã¨ããã ã強調ãã¦åæ²)
ã¾ããã¹ããç¨æãã¾ãã
[kawamoto.m@mm1:~]$ cat 01.t use Test::More; use Test::mysqld; my $mysqld = Test::mysqld->new( my_cnf => { 'skip-networking' => '', # no TCP socket } ) or plan skip_all => $Test::mysqld::errstr; ok(1); done_testing;
perl -d ã§testãèµ°ããã¾ãã
[kawamoto.m@mm1:~]$ perl -d 01.t Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(01.t:4): my $mysqld = Test::mysqld->new( main::(01.t:5): my_cnf => { main::(01.t:6): 'skip-networking' => '', # no TCP socket DB<1> n main::(01.t:10): ok(1); DB<1> x $mysqld 0 Test::mysqld=HASH(0x100ba3908) '_owner_pid' => 63025 'auto_start' => 2 'base_dir' => '/tmp/93XStAoC1x' 'my_cnf' => HASH(0x100812500) 'datadir' => '/tmp/93XStAoC1x/var' 'pid-file' => '/tmp/93XStAoC1x/tmp/mysqld.pid' 'skip-networking' => '' 'socket' => '/tmp/93XStAoC1x/tmp/mysql.sock' 'mysql_install_db' => '/usr/local/bin/mysql_install_db' 'mysqld' => '/usr/local/bin/mysqld' 'pid' => 63071
ãã®ã¨ãsocketã®å¤ãã³ãã¼ãããã¹ãå®è¡åæ¢ä¸ã®ã¾ã¾å¥ã®ã¿ã¼ããã«ãã
$ mysql -uroot -S /tmp/93XStAoC1x/tmp/mysql.sock test
ã§æ¥ç¶ããã°ãã¹ãä¸ã®DBã«æ®éã«æ¥ç¶ã§ãã¾ããå½ããåã¨ããã°å½ããåã§ããã
æ®æ®µprint debugãã¦ãããåã®ã¿ããªã Test::mysqld 使ãã¨ã㯠debugger 使ã£ãã»ããããã§ããã¼
ããã使ãã¨MySQLã®ãã¼ãã«ã®ä¸ãè¦éãã¦çºãããã¨ãã§ããã®ã§åç´ã«å¹çè¯ãããé¢ä¿ãªãå¤ãããããã¦ãã¨ãããããããããããªããã¹ãæ¸ãããã¨ãã§ãã¾ããï¼
DBé¢é£ã®ãã¹ãããããªæãã§ãã£ã¦ãããã¡ã«ãMySQLã¨é¢ä¿ãªãããã°ãperl -dã§ã¹ã ã¼ãºã«ã§ããããã«ãªãã¾ããããã¨èº«é·ä¼¸ã³ã¾ããã彼女ãåºæ¥ã¾ããã zigorou++