本文へ移動
cccskills
無料GitHub で公開

perl-testing

This skill should be used when the user asks to write Perl tests, test Perl code, use Test More, run prove, create test suite, mock Perl, or mentions Perl testing, TAP, Test Class, Test Deep, or test-driven development in Perl.

インストール方法を見る

含まれるファイル(5)

  • SKILL.md7.8 KB
  • references/mock-patterns.md8.7 KB
  • references/test-examples/basic_test.t3.3 KB
  • references/test-examples/exception_test.t4.0 KB
  • references/test-examples/mock_test.t5.9 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Perl Testing Guide

Comprehensive guide for testing Perl code using Test::More, Test::Class, and related modules.

Test::More Basics

The foundation of Perl testing.

Simple Test File

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

# Basic assertions
ok(1, 'truth is true');
ok(!0, 'false is not true');

# Equality
is($got, $expected, 'values are equal');
isnt($got, $unexpected, 'values differ');

# String comparison
is($string, 'expected', 'string matches');
like($string, qr/pattern/, 'matches regex');
unlike($string, qr/bad/, 'does not match regex');

# Numeric comparison
cmp_ok($num, '>', 10, 'greater than 10');
cmp_ok($num, '==', 42, 'equals 42');

# Data structures
is_deeply(\@got, \@expected, 'arrays match');
is_deeply(\%got, \%expected, 'hashes match');

done_testing();

Test Planning

# Declare expected test count
use Test::More tests => 5;

# Or count at end
use Test::More;
# ... tests ...
done_testing();

# Skip remaining tests
use Test::More;
# ... tests ...
done_testing(10);  # Explicit count

Running Tests

prove Command

# Run all tests in t/
prove

# Verbose output
prove -v

# Run specific test
prove t/basic.t

# Recursive with color
prove -r --color

# With library path
prove -l t/  # Adds lib/ to @INC

# Parallel execution
prove -j4

# Shuffle order
prove --shuffle

Common prove Flags

FlagPurpose
-vVerbose TAP output
-lAdd lib/ to @INC
-bAdd blib/ to @INC
-rRecursive directory search
-j NRun N tests in parallel
--colorColored output
--shuffleRandomize test order
--state=saveSave test state

Test Organization

Directory Structure

project/
├── lib/
│   └── MyApp/
│       ├── Module.pm
│       └── Utils.pm
├── t/
│   ├── 00-compile.t
│   ├── 01-basic.t
│   ├── 02-module.t
│   └── lib/
│       └── Test/
│           └── MyApp.pm
└── xt/
    ├── author/
    │   └── pod.t
    └── release/
        └── manifest.t

Compile Test (t/00-compile.t)

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

use_ok('MyApp::Module');
use_ok('MyApp::Utils');

done_testing();

Test::More Functions

Assertions

# Boolean
ok($condition, $description);

# Equality
is($got, $expected, $desc);       # String comparison
isnt($got, $expected, $desc);
cmp_ok($got, $op, $expected, $desc);  # Any operator

# Pattern matching
like($got, qr/pattern/, $desc);
unlike($got, qr/pattern/, $desc);

# Data structures
is_deeply($got, $expected, $desc);

# Reference type
isa_ok($obj, 'ClassName');
can_ok($obj, 'method1', 'method2');

# Pass/fail
pass($desc);
fail($desc);

Diagnostics

# Additional output on failure
is($got, $expected, 'test') or diag("Got: $got");

# Always print
note("Debug info: $value");

# Dump structure
use Data::Dumper;
diag(Dumper($complex_structure));

Skipping and TODO

# Skip tests conditionally
SKIP: {
    skip "No database connection", 3 unless $db;

    ok($db->ping, 'database responds');
    is($db->version, '5.7', 'correct version');
    ok($db->tables > 0, 'has tables');
}

# Mark tests as TODO
TODO: {
    local $TODO = "Feature not implemented";

    is(new_feature(), 'expected', 'new feature works');
}

# Skip all tests in file
plan skip_all => 'Module not installed' unless eval { require Optional::Module };

Test::Exception

Test that code dies or lives correctly.

use Test::More;
use Test::Exception;

# Test that code dies
dies_ok { divide(1, 0) } 'division by zero dies';

# Test that code lives
lives_ok { safe_operation() } 'safe operation lives';

# Test specific exception
throws_ok { bad_call() } qr/invalid argument/i, 'throws expected error';

# Test exception type
throws_ok { bad_call() } 'MyApp::Exception', 'throws correct class';

# Combine with return value
lives_and { is(calc(2, 2), 4) } 'calc lives and returns correct value';

done_testing();

Test::Deep

Deep structure comparison with flexibility.

use Test::More;
use Test::Deep;

# Ignore certain values
cmp_deeply(
    $got,
    {
        id => ignore(),        # Any value
        name => 'test',
        created => re(qr/^\d{4}-\d{2}-\d{2}$/),  # Pattern match
    },
    'structure matches'
);

# Bag comparison (order doesn't matter)
cmp_deeply(
    \@got,
    bag(1, 2, 3),  # Same elements, any order
    'contains all elements'
);

# Subset matching
cmp_deeply(
    $got,
    superhashof({ required => 'value' }),
    'contains required keys'
);

# Type checking
cmp_deeply(
    $data,
    {
        count => code(sub { $_[0] > 0 }),
        items => array_each(isa('MyApp::Item')),
    },
    'types correct'
);

done_testing();

Test::MockModule

Mock module behavior for isolation.

use Test::More;
use Test::MockModule;

# Mock a module
my $mock = Test::MockModule->new('MyApp::Database');

# Replace a method
$mock->mock('connect', sub { return 'fake_handle' });

# Mock with return value
$mock->mock('fetch', sub { return { id => 1, name => 'test' } });

# Verify mock was called
my $called = 0;
$mock->mock('save', sub { $called++; return 1 });

# Run code under test
my $result = MyApp::Service->new->process();

is($called, 1, 'save was called');

# Restore original
$mock->unmock('connect');

done_testing();

Test::Class

Object-oriented testing with setup/teardown.

package Test::MyApp::User;
use parent 'Test::Class';
use Test::More;
use MyApp::User;

# Run before each test method
sub setup : Test(setup) {
    my $self = shift;
    $self->{user} = MyApp::User->new(name => 'Test');
}

# Run after each test method
sub teardown : Test(teardown) {
    my $self = shift;
    $self->{user} = undef;
}

# Test methods
sub test_creation : Test(2) {
    my $self = shift;
    isa_ok($self->{user}, 'MyApp::User');
    is($self->{user}->name, 'Test', 'name is set');
}

sub test_validation : Test(1) {
    my $self = shift;
    ok($self->{user}->is_valid, 'user is valid');
}

# Run all Test::Class tests
Test::Class->runtests;

Test::Class Runner

#!/usr/bin/env perl
# t/run_all.t
use strict;
use warnings;

use lib 't/lib';
use Test::MyApp::User;
use Test::MyApp::Order;

Test::Class->runtests;

Fixtures and Test Data

Test Data Files

use Path::Tiny;
use JSON::PP;

sub load_fixture {
    my ($name) = @_;
    my $file = path("t/fixtures/$name.json");
    return decode_json($file->slurp_utf8);
}

# In test
my $data = load_fixture('users');

Database Fixtures

use Test::More;
use DBI;

my $dbh;

sub setup_test_db {
    $dbh = DBI->connect('dbi:SQLite::memory:', '', '');
    $dbh->do('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
    $dbh->do("INSERT INTO users VALUES (1, 'test')");
}

sub teardown_test_db {
    $dbh->disconnect if $dbh;
}

# Use in tests
setup_test_db();
# ... run tests ...
teardown_test_db();

Coverage

# Install Devel::Cover
cpanm Devel::Cover

# Run tests with coverage
cover -test

# Generate HTML report
cover -report html

# View report
open cover_db/coverage.html

Additional Resources

Reference Files

Related Skills

For modern Perl coding patterns, see the perl-development skill.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Add automated documentation updater to any Claude skill. Creates a Python sync script that downloads upstream docs, processes markdown for AI consumption, and maintains local cache with configurable refresh. Collects template variables, then delegates implementation through 5-phase workflow. Use when adding auto-updating reference documentation to plugins or skills.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月12日 更新

SAM-style feature initiation workflow — discovery through codebase analysis, architecture spec, task decomposition, validation, and context manifest. Use when a user asks to add a feature, plan a feature, or convert an idea into an executable SAM plan.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月12日 更新

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月12日 更新

Browser automation for AI agents using the agent-browser CLI and Playwright. Use when navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, logging into sites, or automating any browser task. Triggers on "open a website", "fill out a form", "click a button", "scrape data", "test this web app", "automate browser actions", or any programmatic web interaction request.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月12日 更新

Runs the description-drift experiment — spawns all Claude Code agents simultaneously to collect self-reported capabilities, then compares them against static frontmatter descriptions to reveal how reliable orchestrator routing based on descriptions actually is. Use when measuring description drift across the agent fleet, re-running the capability collection experiment, analyzing a specific agent's self-reported capabilities, or auditing whether frontmatter descriptions accurately reflect agent behavior.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月12日 更新

Create or adapt Claude Code agent definitions. Use when creating an agent, changing subagent configuration, selecting agent scope, or designing a specialized delegation role.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月12日 更新

Jamie-BitFlight のスキルをすべて見る

このスキルの問題を報告する