<commit_before><commit_msg>Add tests for DTrace setopt options<commit_after>use strict;
use warnings;

use Test::Most;
use IO::File;

use_ok( 'Devel::libdtrace' );

my $libdtrace = Devel::libdtrace->new();

isa_ok( $libdtrace, 'Devel::libdtrace' );
can_ok( $libdtrace, 'setopt'           );

throws_ok( sub { $libdtrace->setopt(); },
           qr/Usage:/, 'NULL option');
throws_ok( sub { $libdtrace->setopt(""); },
           qr/Invalid\soption\sname/,
           'Empty string option' );
throws_ok( sub { $libdtrace->setopt('bogusoption'); },
           qr/Invalid\soption\sname/,
           'Bogus option' );
throws_ok( sub { $libdtrace->setopt('bufpolicy'); },
           qr/Invalid\svalue\sfor\sspecified\soption/,
           'bufpolicy, which requires a value, with no value' );
throws_ok( sub { $libdtrace->setopt('bufpolicy', 100); },
           qr/Value\smust\sbe\sa\sstring/,
           'bufpolicy, with a numeric value' );

#$libdtrace->setopt('quiet', 1);

throws_ok( sub { $libdtrace->setopt('bufpolicy', 1); },
           qr/Value\smust\sbe\sa\sstring/,
           'bufpolicy, with a numeric value #2' );
throws_ok( sub { $libdtrace->setopt('dynvarsize', 1); },
           qr/Value\smust\sbe\sa\sstring/,
           'dynvarsize, with a numeric value');
throws_ok( sub { $libdtrace->setopt('dynvarsize', 1.23); },
           qr/Value\smust\sbe\sa\sstring/,
           'dynvarsize, with a floating point value' );

#$libdtrace->setopt('quiet', 1024);

throws_ok( sub { $libdtrace->setopt('quiet', { foo => 1024 } ); },
           qr/Value\smust\sbe\sa\sstring/,
           'quiet, with a hashref value' );
throws_ok( sub { $libdtrace->setopt('quiet', [ 0 ] ); },
           qr/Value\smust\sbe\sa\sstring/,
           'quiet, with an arrayref value' );
throws_ok( sub { $libdtrace->setopt('quiet', 1.024 ); },
           qr/Value\smust\sbe\sa\sstring/,
           'quiet, with a floating point value' );
throws_ok( sub { $libdtrace->setopt('quiet', IO::File->new("/etc/group","<") ); },
           qr/Value\smust\sbe\sa\sstring/,
           'quiet, with a DateTime object value' );


lives_ok( sub { $libdtrace->setopt('quiet'); },
          'quiet, set properly' );
lives_ok( sub { $libdtrace->setopt('dynvarsize', '16m'); },
          'dynvarsize, with 16m value' );
lives_ok( sub { $libdtrace->setopt('bufpolicy', 'ring'); },
          'bufpolicy, with "ring" value' );

done_testing();


{'fraction_non_alphanumeric': 0.18143986683312527, 'fraction_numerical': 0.011235955056179775, 'mean_word_length': 2.8962722852512157, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4062283', 'n_tokens_mistral': 887, 'n_tokens_neox': 836, 'n_words': 167}