Test::API(3)

🌸 NAME 🌸

okay bestie, welcome to the Test::API manual page β€” that's Test::API(3) if you're looking at the man page header, iykyk. Test::API - Test a list of subroutines provided by a module. That's the whole name vibe.

✨ VERSION ✨

version 0.010 β€” exact number, no cap. πŸ’–

🧚 SYNOPSIS 🧚

use Test::More tests => 3;
use Test::API;

require_ok( 'My::Package' );

public_ok ( 'My::Package', @names );

import_ok ( 'My::Package',
    export    => [ 'foo', 'bar' ],
    export_ok => [ 'baz', 'bam' ],
);

class_api_ok( 'My::Class', @methods );

πŸ’– DESCRIPTION πŸ’–

This simple test module checks the subroutines provided by a module. It's useful for confirming a planned API in testing and ensuring that other functions aren't unintentionally included via import. Literally the vibe check for your package's API. ✨

πŸŽ€ USAGE πŸŽ€

Note, bestie: Subroutines starting with an underscore are ignored, as are a number of other methods not intended to be called directly by end-users. So don't come for them, okay? πŸ’…

Here's the whole ignored-methods list, copied exactly because we do not mess with the facts:

import unimport bootstrap

AUTOLOAD BUILD BUILDARGS CLONE CLONE_SKIP DESTROY DEMOLISH

TIESCALAR TIEARRAY TIEHASH TIEHANDLE

FETCH STORE UNTIE FETCHSIZE STORESIZE POP PUSH SHIFT UNSHIFT SPLICE
DELETE EXISTS EXTEND CLEAR FIRSTKEY NEXTKEY PRINT PRINTF WRITE
READLINE GETC READ CLOSE BINMODE OPEN EOF FILENO SEEK TELL SCALAR

MODIFY_REF_ATTRIBUTES MODIFY_SCALAR_ATTRIBUTES MODIFY_ARRAY_ATTRIBUTES
MODIFY_HASH_ATTRIBUTES MODIFY_CODE_ATTRIBUTES MODIFY_GLOB_ATTRIBUTES
MODIFY_FORMAT_ATTRIBUTES MODIFY_IO_ATTRIBUTES

FETCH_REF_ATTRIBUTES FETCH_SCALAR_ATTRIBUTES FETCH_ARRAY_ATTRIBUTES
FETCH_HASH_ATTRIBUTES FETCH_CODE_ATTRIBUTES FETCH_GLOB_ATTRIBUTES
FETCH_FORMAT_ATTRIBUTES FETCH_IO_ATTRIBUTES

Therefore, do not include any of these in a list of expected subroutines. That's the rule, bestie, do not break it. πŸ™ˆ

πŸ’… public_ok πŸ’…

public_ok( $package, @names );

This function checks that all of the @names provided are available within the $package namespace and that only these subroutines are available. This means that subroutines imported from other modules will cause this test to fail unless they are explicitly included in @names. So if some random import sneaks in, the test's gonna be like "not today" πŸ’€.

πŸ¦‹ class_api_ok πŸ¦‹

class_api_ok( $class, @names );

A variation of public_ok for object-oriented modules. Allows superclasses to fill in "missing" subroutines, but "extra" methods provided by superclasses will not cause the test to fail. It's giving inheritance-friendly, no cap. πŸ‘‘

πŸ“ import_ok πŸ“

import_ok ( $package, %spec );

This function checks that $package correctly exports an expected list of subroutines and only these subroutines. The %spec generally follows the style used by [Exporter], but in lower case:

%spec = (
  export    => [ 'foo', 'bar' ],  # exported automatically
  export_ok => [ 'baz', 'bam' ],  # optional exports
);

For export_ok, the test will check for public functions not listed in export or export_ok that can be imported and will fail if any are found. So it's strict, but make it fashion. πŸ’…

πŸ”₯ SEE ALSO πŸ”₯

  • Test::ClassAPI -- more geared towards class trees with inheritance

🫢 SUPPORT 🫢

πŸ› Bugs / Feature Requests πŸ›

Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/Test-API/issues>. You will be notified automatically of any progress on your issue. That's your hotline, bestie. ☎️

πŸ“¦ Source Code πŸ“¦

This is open source software. The code repository is available for public review and contribution under the terms of the license.

<https://github.com/dagolden/Test-API>

git clone https://github.com/dagolden/Test-API.git

πŸ‘‘ AUTHOR πŸ‘‘

David Golden <dagolden@cpan.org>

🌈 CONTRIBUTORS 🌈

  • cpansprout <cpansprout@gmail.com>
  • Toby Inkster <mail@tobyinkster.co.uk>

This software is Copyright (c) 2018 by David Golden.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

okay that's the whole page β€” mwah πŸ’‹ β€” brought to you by perl v5.42.0, dated 2019-03-29, and yes bestie it's Test::API(3). Go slay those API tests. πŸŽ€βœ¨

πŸ“¦ where this page comes from