From 14b5093bf153b034e68f14250bf565c2c1406ad7 Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Sun, 1 Jul 2018 17:45:13 -0400 Subject: [PATCH] Fake a JSON module to make --pretend work without kde-build-metadata. This is mostly to make the testsuite run, which is not supposed to pull down kde-build-metadata, though it may be worth it to construct a suitable "fake metadata" instead. --- modules/ksb/Updater/KDEProjectMetadata.pm | 5 +++-- modules/ksb/Util.pm | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ksb/Updater/KDEProjectMetadata.pm b/modules/ksb/Updater/KDEProjectMetadata.pm index c0489fc..ddeb9ad 100644 --- a/modules/ksb/Updater/KDEProjectMetadata.pm +++ b/modules/ksb/Updater/KDEProjectMetadata.pm @@ -49,7 +49,8 @@ sub logicalModuleGroups my $self = shift; my $path = $self->module()->fullpath('source') . "/logical-module-structure"; - my $fh = pretend_open($path) or + # The {} is an empty JSON obj to support pretend mode + my $fh = pretend_open($path, '{}') or croak_internal("Unable to read logical module structure: $!"); my ($json_hashref, $e) = do { @@ -61,7 +62,7 @@ sub logicalModuleGroups ($json, $@); # Implicit return }; - croak_runtime ("Unable to load module group data! :(\n\t$e") if $e; + croak_runtime ("Unable to load module group data from $path! :(\n\t$e") if $e; return $json_hashref; } diff --git a/modules/ksb/Util.pm b/modules/ksb/Util.pm index 48d84ce..5331fdd 100644 --- a/modules/ksb/Util.pm +++ b/modules/ksb/Util.pm @@ -628,6 +628,7 @@ sub download_file # # Parameters: # filename - Path to the file to open. +# default - String to use if the file doesn't exist in pretend mode # # Returns: # filehandle on success (supports readline() and eof()), can return boolean @@ -636,11 +637,11 @@ sub download_file sub pretend_open { my $path = shift; + my $defaultText = shift // ''; my $fh; if (pretending() && ! -e $path) { - my $simulatedFile = ''; - open $fh, '<', \$simulatedFile or return; + open $fh, '<', \$defaultText or return; } else { open $fh, '<', $path or return;