Skip to content

Instantly share code, notes, and snippets.

@preaction
Created November 16, 2017 22:46
Show Gist options
  • Select an option

  • Save preaction/2bf63be7a4d54c97aa0219d2ad5a5a6f to your computer and use it in GitHub Desktop.

Select an option

Save preaction/2bf63be7a4d54c97aa0219d2ad5a5a6f to your computer and use it in GitHub Desktop.
Build a small test file from the CPAN Testers API for testing
#!/bin/bash
cd `dirname "$0"`
cd ..
url=http://api.cpantesters.org/v3/release
in=t/var/tmp/cpantesters-release-api.json
out=t/var/cpantesters-release-api-fake.json
download_original () {
test -s "$in" || wget -O "$in" "$url"
}
append_json () {
perl -MJSON::PP -e'
$file = shift;
$all = -e $file ? decode_json(
do { local $/; open $fh, "<", $file; <$fh> }
) : [];
$add = decode_json( join "", <STDIN> );
push @$all, $add;
open $fh, ">", $file;
print { $fh } encode_json( $all ) ' $out
}
collect_dist () {
local dist="$1" version="$2"
jq '.[] | select( .dist == $dist and .version == $version )' \
--arg dist "$dist" --arg version "$version" $in \
| append_json
}
fake_dist () {
echo "{ \"dist\": \"$1\", \"version\": \"$2\", \"pass\": $3, \"fail\": $4, \
\"na\": $5, \"unknown\": $6 }" | append_json;
}
populate_file () {
rm -f "$out"
# Get test cases from real data.
collect_dist 'Devel-GoFaster' '0.000'
collect_dist 'P' '1.0.20'
collect_dist 'IPsonar' '0.29'
collect_dist 'weblint' '++-1.15'
collect_dist 'WWW-Tumblr' ''
# Add records for our fake dists.
fake_dist 'Some' '1.00-TRIAL' 4 3 2 1
}
download_original
populate_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment