Skip to content

Commit

Permalink
Generate symlinks properly for multi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Jan 17, 2022
1 parent a4f3c1e commit 8cf790b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 56 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ data:
data-update: data
rm -fr $</*
suite-to-data src/*.yaml
data-symlinks $<

data-status: data
@git -C $< add -Af . && \
Expand Down
11 changes: 10 additions & 1 deletion bin/YAMLTestSuite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,23 @@ sub run {
$self->{make}++;
$self->{data} = $test;
$self->{num} = sprintf "%0${l}d", $i++;
$self->{ID} = $multi
my $ID = $self->{ID} = $multi
? "$self->{id}-$self->{num}"
: $self->{id};

die "Can't change test name in '$ID'"
if $test->{name} and $cache->{name};

$test->{name} ||= $cache->{name} or die;
$test->{tags} ||= $cache->{tags} || '';
$test->{yaml} ||= $cache->{yaml} or die;
$test->{fail} = exists $test->{fail} ? 1 : 0;

$self->{slug} = lc $test->{name};
$self->{slug} =~ s/[^\w]+/-/g;
$self->{slug} =~ s/^-//;
$self->{slug} =~ s/-$//;

for my $key (qw< tree json dump emit toke >) {
if (
not exists $test->{$key} and
Expand Down
47 changes: 0 additions & 47 deletions bin/data-symlinks

This file was deleted.

35 changes: 28 additions & 7 deletions bin/suite-to-data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use lib $FindBin::Bin;
use base 'YAMLTestSuite';
use Encode;
use File::Path qw(make_path);

my %map = (
'name' => '===',
Expand All @@ -24,20 +25,25 @@
'toke' => 'lex.token',
);

die "'data' directory not empty" if glob('data/*');
mkdir my $meta_dir = "data/meta";
mkdir my $name_dir = "data/name";
mkdir my $tags_dir = "data/tags";

main->new->run([@ARGV]);

sub make {
my ($self) = @_;

my ($id, $ID, $num, $data, $multi) =
@$self{qw<id ID num data multi>};
my ($id, $ID, $num, $data, $multi, $slug) =
@$self{qw<id ID num data multi slug>};

my $dir = "data/$id";
mkdir $dir unless -d $dir;
my $test_dir = "data/$id";
mkdir $test_dir unless -d $test_dir;

if ($multi) {
$dir .= "/$num";
mkdir $dir or die $dir;
$test_dir .= "/$num";
mkdir $test_dir or die $test_dir;
}

for my $k (sort keys %map) {
Expand All @@ -57,11 +63,26 @@ sub make {

$_ = $self->unescape($_);

open my $out, '>', "$dir/$map{$k}" or die;
open my $out, '>', "$test_dir/$map{$k}" or die;
print $out encode_utf8($_);
close $out;
}
}

if ($num == 0) {
symlink $data->{name}, "$meta_dir/$id.label";
symlink "../$id", "$name_dir/$slug";
}

for my $tag (split /\s+/, $data->{tags}) {
mkdir "$tags_dir/$tag";
if ($multi) {
symlink "../../$id/$num", "$tags_dir/$tag/$id-$num";
}
else {
symlink "../../$id", "$tags_dir/$tag/$id";
}
}
}

sub final {
Expand Down

0 comments on commit 8cf790b

Please sign in to comment.