Config-Abstraction

 view release on metacpan or  search on metacpan

t/edge_cases.t  view on Meta::CPAN

	# not abort construction.  data values must survive.
	plan skip_all => 'TOML::Tiny not installed' unless eval { require TOML::Tiny; 1 };

	my $dir = tempdir(CLEANUP => 1);
	_write_file($dir, 'base.toml', qq{host = "unclosed string\n});

	my @warnings;
	local $SIG{__WARN__} = sub { push @warnings, $_[0] };

	my $cfg = Config::Abstraction->new(
		data        => { fallback => 'alive' },
		config_dirs => [$dir],
		env_prefix  => $ENV_PREFIX,
	);
	ok(@warnings > 0, 'malformed TOML emits at least one carp warning');
	ok(defined($cfg), 'construction succeeds despite malformed base.toml');
	is($cfg->get('fallback'), 'alive', 'data values survive a malformed TOML file');
};

subtest 'TOML: config_file with .toml extension is loaded via extensionless chain' => sub {
	# When config_file points to a .toml file, the all-parsers chain
	# should try TOML::Tiny and succeed.
	plan skip_all => 'TOML::Tiny not installed' unless eval { require TOML::Tiny; 1 };

	my $dir = tempdir(CLEANUP => 1);
	_write_file($dir, 'myapp.toml', qq{[server]\nhost = "explicit_host"\nport = 9000\n});

t/extended_tests.t  view on Meta::CPAN

	my $cfg = Config::Abstraction->new(config_dirs => []);
	ok(!defined($cfg), 'constructor returns undef when no configuration data found');
};

# Similarly: constructor returns undef when only config_dirs is absent key=
# (calling new without any arguments at all uses default dirs, but if those
# dirs don't exist on this machine, config will be empty)
subtest 'new() - returns defined object when in-memory data is provided' => sub {
	# With data arg, config is always non-empty → line 422 TRUE → returns $self
	my $cfg = Config::Abstraction->new(
		data        => { alive => 1 },
		config_dirs => [],
	);
	ok(defined($cfg), 'constructor returns defined object with in-memory data');
	is($cfg->get('alive'), 1, 'in-memory data accessible');
};

# ===========================================================================
# _parse_remote_dir() -- branch coverage for $2 // '/' fallback (line 1154)
# ===========================================================================

# `_parse_remote_dir` is NOT access-guarded, so it can be called directly.
# When the path has no directory component after the hostname (e.g., /../host),
# capture group $2 is undef → `$2 // '/'` returns '/' (line 1154 fallback).
subtest '_parse_remote_dir() - hostname with no path uses / as default' => sub {

t/mutant_killers.t  view on Meta::CPAN

	{
		no warnings 'once';
		local *MKLogger2::warn    = sub { push @warns, $_[1] };
		local *MKLogger2::notice  = sub { push @warns, $_[1] };
		local *MKLogger2::debug   = sub { };
		local *MKLogger2::trace   = sub { };

		my $cfg;
		_silenced(sub {
			$cfg = Config::Abstraction->new(
				data        => { sentinel => 'alive' },
				config_dirs => [$dir],
				logger      => $logger,
			);
		});
		# Data from data hash should survive even if XML parsing failed
		ok(defined($cfg), 'object created despite XML parse failure');
		is($cfg->get('sentinel'), 'alive', 'data sentinel survives parse error');
	}
};

subtest '_load_config() - only HASH data merged into source records (COND_INV_1512_5)' => sub {
	my $dir = tempdir(CLEANUP => 1);
	_write_file($dir, 'base.yaml', "db:\n  host: localhost\n  port: 5432\n");

	my $cfg = Config::Abstraction->new(config_dirs => [$dir]);
	ok(defined($cfg), 'nested YAML loaded');
	is($cfg->get('db.host'), 'localhost', 'nested key merged into config');



( run in 1.324 second using v1.01-cache-2.11-cpan-14f38c9f855 )