File: README.md

package info (click to toggle)
libtest-synopsis-expectation-perl 0.12-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 216 kB
  • sloc: perl: 303; makefile: 2; sh: 1
file content (234 lines) | stat: -rw-r--r-- 5,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
[![Build Status](https://travis-ci.org/moznion/Test-Synopsis-Expectation.svg?branch=master)](https://travis-ci.org/moznion/Test-Synopsis-Expectation) [![Coverage Status](https://img.shields.io/coveralls/moznion/Test-Synopsis-Expectation/master.svg)](https://coveralls.io/r/moznion/Test-Synopsis-Expectation?branch=master)
# NAME

Test::Synopsis::Expectation - Test that SYNOPSIS code produces expected results

# SYNOPSIS

    use Test::Synopsis::Expectation;

    synopsis_ok('eg/sample.pod');
    done_testing;

Following, SYNOPSIS of `eg/sample.pod`

    my $num;
    $num = 1; # => 1
    ++$num;   # => is 2

    use PPI::Tokenizer;
    my $tokenizer = PPI::Tokenizer->new(\'code'); # => isa 'PPI::Tokenizer'

    my $str = 'Hello, I love you'; # => like qr/ove/

    my $obj = {
        foo => ["bar", "baz"],
    }; # => is_deeply { foo => ["bar", "baz"] }

    my $bool = 1; # => success

# DESCRIPTION

This module checks that a module's SYNOPSIS section is syntactically correct,
and will also check that it produces the expected results,
based on annotations you add in comments.

# FUNCTIONS

- synopsis\_ok($files)

    This function tests SYNOPSIS codes of each files.
    This function expects file names as an argument as ARRAYREF or SCALAR.
    (This function is exported)

- all\_synopsis\_ok()

    This function tests SYNOPSIS codes of the all of library files.
    This function uses `MANIFEST` to list up the target files of testing.
    (This function is exported)

- prepare($code\_str)

    Register the executable codes to prepare for evaluation.

    If you use like;

        use Test::Synopsis::Expectation;
        Test::Synopsis::Expectation::prepare('my $foo = 1;');
        synopsis_ok('path/to/target.pm');
        done_testing;

        ### Following, SYNOPSIS of `target.pm`
        $foo; # => 1

    Then, SYNOPSIS of `target.pm` is the same as;

        my $foo = 1;
        $foo; # => 1

    (This function is not exported)

- set\_ignorings

    Set the procedures which would like to ignore.

        use Test::Synopsis::Expectation;
        Test::Synopsis::Expectation::set_ignorings(['++$num;']);
        synopsis_ok(*DATA);
        done_testing;

        __DATA__
        =head1 SYNOPSIS

            my $num;
            $num = 1; # => 1
            ++$num;
            $num; # => 1

    In the above example, `++$num;` will be ignored.

# NOTATION OF EXPECTATION

Comment that starts at `# =>` then this module treats the comment as test statement.

- # => is

        my $foo = 1; # => is 1

    This way is equivalent to the next.

        my $foo = 1;
        is $foo, 1;

    This carries out the same behavior as `Test::More::is`.

- # =>

        my $foo = 1; # => 1

    This notation is the same as `# => is`

- # => isa

        use Foo::Bar;
        my $instance = Foo::Bar->new; # => isa 'Foo::Bar'

    This way is equivalent to the next.

        use Foo::Bar;
        my $instance = Foo::Bar->new;
        isa_ok $instance, 'Foo::Bar';

    This carries out the same behavior as `Test::More::isa_ok`.

- # => like

        my $str = 'Hello, I love you'; # => like qr/ove/

    This way is equivalent to the next.

        my $str = 'Hello, I love you';
        like $str, qr/ove/;

    This carries out the same behavior as `Test::More::like`.

- # => is\_deeply

        my $obj = {
            foo => ["bar", "baz"],
        }; # => is_deeply { foo => ["bar", "baz"] }

    This way is equivalent to the next.

        my $obj = {
            foo => ["bar", "baz"],
        };
        is_deeply $obj, { foo => ["bar", "baz"] };

    This carries out the same behavior as `Test::More::is_deeply`.

- # => success

        my $bool = 1;
        $bool; # => success

    This way checks value as boolean.
    If target value of testing is 0 then this test will fail. Otherwise, it will pass.

# ANNOTATIONS

- =for test\_synopsis\_expectation\_no\_test

    The code block behind this annotation will not be tested.

            my $sum;
            $sum = 1; # => 1

        =for test_synopsis_expectation_no_test

            my $sum;
            $sum = 1; # => 2

    In this example, the first code block will be tested, but the second will not.

# RESTRICTION

## Test case must be one line

The following is valid;

    my $obj = {
        foo => ["bar", "baz"],
    }; # => is_deeply { foo => ["bar", "baz"] }

However, the following is invalid;

    my $obj = {
        foo => ["bar", "baz"],
    }; # => is_deeply {
       #        foo => ["bar", "baz"]
       #    }

So test case must be one line.

## Not put test cases inside of for(each)

    # Example of not working
    for (1..10) {
        my $foo = $_; # => 10
    }

This example doesn't work. On the contrary, it will be error (Probably nobody uses such as this way... I think).

# NOTES

## yada-yada operator

This module ignores yada-yada operators that is in SYNOPSIS code.
Thus, following code is runnable.

    my $foo;
    ...
    $foo = 1; # => 1

# SEE ALSO

[Test::Synopsis](https://metacpan.org/pod/Test::Synopsis) - simpler module, which just checks the syntax of your SYNOPSIS section.

[Dist::Zilla::Plugin::Test::Synopsis](https://metacpan.org/pod/Dist::Zilla::Plugin::Test::Synopsis) - a plugin for [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) users, which adds a release test
to your distribution, based on [Test::Synopsis](https://metacpan.org/pod/Test::Synopsis).

# REPOSITORY

[https://github.com/moznion/Test-Synopsis-Expectation](https://github.com/moznion/Test-Synopsis-Expectation)

# LICENSE

Copyright (C) moznion.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

# AUTHOR

moznion <moznion@gmail.com>