File: import_spew_bypass.pl

package info (click to toggle)
golang-github-maxatome-go-testdeep 1.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,416 kB
  • sloc: perl: 1,012; yacc: 130; makefile: 2
file content (43 lines) | stat: -rwxr-xr-x 1,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env perl

# Copyright (c) 2018, Maxime Soulé
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

use strict;
use warnings;
use autodie;
use 5.014;

use HTTP::Tiny;

my $SPEW_BASE_URL =
    'https://raw.githubusercontent.com/davecgh/go-spew/master/spew/';

foreach my $file (qw(bypass.go bypasssafe.go))
{
    my $resp = HTTP::Tiny::->new->get("$SPEW_BASE_URL$file");
    $resp->{success} or die "Failed to retrieve $file!\n";

    unless ($resp->{content} =~ s/^package \Kspew$/dark/m)
    {
        die "'package spew' line not found in $file!\n";
    }

    open(my $fh, '>', "internal/dark/$file");

    say $fh <<EOH;
// DO NOT EDIT!!! AUTOMATICALLY COPIED FROM
// https://github.com/davecgh/go-spew/blob/master/spew/$file
EOH

    my %ops = (',' => ' && ', ' ' => ' || ');
    $resp->{content} =~
        s{^(?=// \+build (.*))}
         {"//go:build " . ($1 =~ s!([ ,])!$ops{$1}!gr) . "\n"}em;
    print $fh $resp->{content};

    close $fh;
}