Changeset 2497f99 for t


Ignore:
Timestamp:
Jun 14, 2013, 7:39:23 PM (8 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master
Children:
5d8c9a7
Parents:
80c0fc7
git-author:
Robert Jacobs <rnjacobs@mit.edu> (06/04/13 19:19:44)
git-committer:
David Benjamin <davidben@mit.edu> (06/14/13 19:39:23)
Message:
Add tests to detect new_variable_* overriding previously set values

[davidben@mit.edu: Fix some nits]
File:
1 edited

Legend:

Unmodified
Added
Removed
  • t/variable.t

    r4953c44 r2497f99  
    1717BarnOwl::unset("-q", "intvar");
    1818is(BarnOwl::getvar("intvar"), "24", "intvar unset bogus");
     19BarnOwl::new_variable_int("intvar", { default => 7 });
     20isnt(BarnOwl::getvar("intvar"), "7", "intvar reinit shouldn't override preexisting value");
    1921
    2022BarnOwl::new_variable_bool("boolvar", { default => 1 });
     
    2830BarnOwl::unset("-q", "boolvar");
    2931is(BarnOwl::getvar("boolvar"), "off", "boolvar unset");
     32BarnOwl::new_variable_bool("boolvar", { default => 1 });
     33isnt(BarnOwl::getvar("boolvar"), "on", "boolvar reinit shouldn't override preexisting value");
    3034
    3135BarnOwl::new_variable_string("strvar", { default => "monkey" });
     
    3741BarnOwl::unset("-q", "strvar");
    3842is(BarnOwl::getvar("strvar"), "cuttlefish", "strvar unset bogus");
     43BarnOwl::new_variable_string("strvar", { default => "monkey" });
     44isnt(BarnOwl::getvar("strvar"), "monkey", "strvar reinit shouldn't override value");
    3945
    4046BarnOwl::new_variable_enum("enumvar", { validsettings => [qw/foo bar baz/], default => "bar" });
     
    4652BarnOwl::unset("-q", "enumvar");
    4753is(BarnOwl::getvar("enumvar"), "baz", "enumvar unset bogus");
     54BarnOwl::new_variable_enum("enumvar", { validsettings => [qw/foo bar baz/], default => "bar" });
     55isnt(BarnOwl::getvar("enumvar"), "bar", "enumvar reinit shouldn't override value");
    4856
    4957BarnOwl::new_variable_int("intvar2");
     
    6270    get_tostring => sub { "value is " . $value },
    6371    set_fromstring => sub {
    64         die "Too long" unless $_[0] =~ /^...?$/;
    65         $value = $_[0];
     72        die "Too long" unless $_[0] =~ /^...?$/;
     73        $value = $_[0];
    6674    },
    6775    takes_on_off => 1
     
    7886$value = "something really long";
    7987is(BarnOwl::getvar("fullvar"), "value is something really long", "fullvar set out-of-band");
     88# Kinda verbose, but better to test all forms
     89my $value = "foo";
     90BarnOwl::new_variable_full("fullvar", {
     91    validsettings => '<short-words>',
     92    get_tostring => sub { "value is " . $value },
     93    set_fromstring => sub {
     94        die "Too long" unless $_[0] =~ /^...?$/;
     95        $value = $_[0];
     96    },
     97    takes_on_off => 1
     98});
     99isnt(BarnOwl::getvar("fullvar"), "value is foo", "fullvar reinit doesn't override value");
    80100
    811011;
Note: See TracChangeset for help on using the changeset viewer.