gctaylor1 has asked for the wisdom of the Perl Monks concerning the following question:
I think it's a simple concatenation problem, but I can't get it right.
In the tests below, 1, 2, 3, and 4 give the expected behavior.
However tests 5, 6, and 7 give me false positives.
I am interpreting the false positives as defined is only looking to see whether a value exists, which it does. However, &Mysimple_mod::bogus does not exist. I'm aware of using not_ok, but for this question I'm not trying to test for non-existent subroutines, I want to accurately make sure it is there. Later on in my journey I plan to write tests that actually use the subroutines. You'll see a few of my failed attempts in the .t file below.
The results:
Here's my test file:1..7 ok 1 - use Mysimple_mod; ok 2 - \#2 external is defined ok 3 - \#3 internal is defined not ok 4 - \#4 bogus subroutine # Failed test '\#4 bogus subroutine' # in test_Mysimple_mod.t at line 11. ok 5 - \#5 bogus subroutine ok 6 - \#6 bogus subroutine &Mysimple_mod::bogus ok 7 - \#7 bogus subroutine # Looks like you failed 1 test of 7.
use strict; use warnings; use Test::More tests => 7; my $val = '&Mysimple_mod'; BEGIN { use_ok('Mysimple_mod', qw (external) ) }; ok ( defined( &external ) , "#2 external is defined"); ok ( defined( &Mysimple_mod::internal ) , "#3 internal is defined"); ok ( defined( &Mysimple_mod::bogus ) , "#4 bogus subroutine"); ok ( defined( "${val}".'::bogus' ) , "#5 bogus subroutine"); ok ( defined( ${val}.'::bogus' ) , "#6 bogus subroutine"); my $catval = "${val}" .'::bogus'; print "\n$catval\n"; ok ( defined( $catval ) , "#7 bogus subroutine");
I'm frequently asked "what are you trying to do, what is your overall goal?"#!/usr/bin/perl package Mysimple_mod; use strict; use warnings; require Exporter; our @ISA=qw(Exporter); our @EXPORT_OK = qw( external ); sub external { my $val = shift; my $return_val = internal($val); return $return_val; } sub internal { my $val = shift; my $calc = $val * 3; return $calc; } 1;
Any and all feedback welcome. Thank-you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Concatenate strings before Test::More::ok
by zwon (Abbot) on Apr 19, 2009 at 20:19 UTC | |
by gctaylor1 (Hermit) on Apr 20, 2009 at 00:21 UTC | |
|
Re: Concatenate strings before Test::More::ok
by almut (Canon) on Apr 19, 2009 at 20:19 UTC | |
|
Re: Concatenate strings before Test::More::ok
by AnomalousMonk (Archbishop) on Apr 20, 2009 at 00:34 UTC | |
|
Re: Concatenate strings before Test::More::ok
by JavaFan (Canon) on Apr 20, 2009 at 22:26 UTC |