1#!perl
2
3# Test suite for Readonly::XS.
4
5use strict;
6use warnings;
7package Readonly;
8use Test::More tests => 10;
9
10use vars qw/$x $y/;
11
12# Find the module (2 tests)
13BEGIN
14{
15    eval 'use Readonly::XS';
16    $@ =~ s/ at .*// if $@;
17    is substr($@,0,71) => "Readonly::XS is not a standalone module. You should not use it directly", 'Unauthorized use';
18
19    $Readonly::XS::MAGIC_COOKIE = "Do NOT use or require Readonly::XS unless you're me.";
20    delete $INC{'Readonly/XS.pm'};
21    eval 'use Readonly::XS';
22    is $@ => '', 'Authorized use';
23}
24
25# Functions loaded?  (2 tests)
26ok defined &is_sv_readonly,   'is_sv_readonly loaded';
27ok defined &make_sv_readonly, 'make_sv_readonly loaded';
28
29# is_sv_readonly (4 tests)
30ok is_sv_readonly("hello"), 'constant string is readonly';
31ok is_sv_readonly(7),       'constant number is readonly';
32*x = \42;
33ok is_sv_readonly($x),      'constant typeglob thingy is readonly';
34$y = 'r/w';
35ok !is_sv_readonly($y),     'inconstant variable is not readonly';
36
37# make_sv_readonly (2 tests)
38make_sv_readonly($y);
39ok is_sv_readonly($y),      'status changed to readonly';
40eval {$y = 75};
41$@ =~ s/ at .*// if $@;
42is $@ => "Modification of a read-only value attempted\n", 'verify readonly-ness';
43