Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save notbenh/617457 to your computer and use it in GitHub Desktop.
Save notbenh/617457 to your computer and use it in GitHub Desktop.
test to illustrate that qw{} is a list
#!/usr/bin/perl
use strict;
use warnings;
use Test::Most qw{no_plan};
sub some ($$;$) { \@_ }
sub many (@) { \@_ }
eq_or_diff(
some(1,qw{2 3}),
[1..3],
q{What I wanted to do, but it fails...}
);
eq_or_diff(
some(1,('2', '3')),
[1..3],
q{... because what I really was saying was ...},
);
eq_or_diff(
some(1,'2','3'),
[1..3],
q{... when I though that I was saying this.},
);
eq_or_diff(
many(1,qw{2 3}),
[1..3],
q{It seems inconstant when this works.},
);
is q{Useless use of a constant in void context},
q{wrong context encountered at sub prototype, list found for scalar prototype at line X.},
q{warnings does find this, but it seems that the wording could be improved.}
;
__END__
Useless use of a constant in void context at /home/benh/tmp/proto.t line 9.
Useless use of a constant in void context at /home/benh/tmp/proto.t line 15.
not ok 1 - What I wanted to do, but it fails...
# Failed test 'What I wanted to do, but it fails...'
# at /home/benh/tmp/proto.t line 8.
# +----+-----+----+----------+
# | Elt|Got | Elt|Expected |
# +----+-----+----+----------+
# | 0|1 | 0|1 |
# | | * 1|2 *
# | 1|3 | 2|3 |
# +----+-----+----+----------+
not ok 2 - ... because what I really was saying was ...
# Failed test '... because what I really was saying was ...'
# at /home/benh/tmp/proto.t line 14.
# +----+-----+----+----------+
# | Elt|Got | Elt|Expected |
# +----+-----+----+----------+
# | 0|1 | 0|1 |
# | | * 1|2 *
# | 1|3 | 2|3 |
# +----+-----+----+----------+
ok 3 - ... when I though that I was saying this.
ok 4 - It seems inconstant when this works.
not ok 5 - warnings does find this, but it seems that the wording could be improved.
# Failed test 'warnings does find this, but it seems that the wording could be improved.'
# at /home/benh/tmp/proto.t line 32.
# got: 'Useless use of a constant in void context'
# expected: 'wrong context encountered at sub prototype, list found for scalar prototype at line X.'
1..5
# Looks like you failed 3 tests of 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment