mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #1746 from fwalch/improve-legacy2luatest
Improve legacy2luatest script.
This commit is contained in:
commit
68637debf6
@ -58,11 +58,12 @@ sub read_in_file {
|
||||
unshift @{$command_lines}, @{$input_lines};
|
||||
unshift @{$command_lines}, "insert([[";
|
||||
|
||||
push @{$test_body_lines}, @{$command_lines};
|
||||
|
||||
@{$command_lines} = ();
|
||||
@{$input_lines} = ();
|
||||
}
|
||||
|
||||
# Output remaining command lines.
|
||||
push @{$test_body_lines}, @{$command_lines};
|
||||
@{$command_lines} = ();
|
||||
}
|
||||
|
||||
sub format_comment {
|
||||
@ -173,11 +174,9 @@ sub read_in_file {
|
||||
$state = $states{$state}->($_);
|
||||
}
|
||||
|
||||
# If not all input lines have been processed,
|
||||
# If not all lines have been processed yet,
|
||||
# do it now.
|
||||
if (@input_lines) {
|
||||
end_input \@input_lines, \@command_lines, \@test_body_lines;
|
||||
}
|
||||
|
||||
close $in_file_handle;
|
||||
|
||||
@ -226,13 +225,17 @@ if ($#ARGV != 1) {
|
||||
}
|
||||
|
||||
my @legacy_suffixes = ('.in', '.ok');
|
||||
my ($test_name, $base_path, $suffix) = fileparse($legacy_testfile, @legacy_suffixes);
|
||||
my $in_file = catfile($base_path, $test_name . '.in');
|
||||
my $ok_file = catfile($base_path, $test_name . '.ok');
|
||||
my ($base_name, $base_path, $suffix) = fileparse($legacy_testfile, @legacy_suffixes);
|
||||
my $in_file = catfile($base_path, $base_name . '.in');
|
||||
my $ok_file = catfile($base_path, $base_name . '.ok');
|
||||
|
||||
# Remove leading 'test'.
|
||||
my $test_name = $base_name;
|
||||
$test_name =~ s/^test_?//;
|
||||
|
||||
my $spec_file = do {
|
||||
if ($test_name =~ /^test([0-9]+)/) {
|
||||
catfile($out_dir, sprintf('%03d', $1) . '_' . $test_name . '_spec.lua')
|
||||
if ($test_name =~ /^([0-9]+)/) {
|
||||
catfile($out_dir, sprintf('%03d', $1) . '_spec.lua')
|
||||
} else {
|
||||
catfile($out_dir, $test_name . '_spec.lua')
|
||||
}
|
||||
@ -250,8 +253,14 @@ if (! -d $out_dir) {
|
||||
|
||||
if (-f $spec_file) {
|
||||
say "Output file $spec_file already exists.";
|
||||
print "Overwrite (Y/n)? ";
|
||||
my $input = <STDIN>;
|
||||
chomp($input);
|
||||
unless ($input =~ /^y|Y/) {
|
||||
say "Aborting.";
|
||||
exit 4;
|
||||
}
|
||||
}
|
||||
|
||||
# Read .in and .ok files.
|
||||
my ($description_lines, $test_body_lines) = read_in_file $in_file;
|
||||
@ -267,8 +276,8 @@ print $spec_file_handle <<"EOS";
|
||||
@{[join "\n", @{$description_lines}]}
|
||||
|
||||
local helpers = require('test.functional.helpers')
|
||||
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
|
||||
local execute, expect = helpers.execute, helpers.expect
|
||||
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
||||
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
|
||||
|
||||
describe('$test_name', function()
|
||||
setup(clear)
|
||||
@ -280,3 +289,5 @@ end)
|
||||
EOS
|
||||
|
||||
close $spec_file_handle;
|
||||
|
||||
say "Written to $spec_file."
|
||||
|
Loading…
Reference in New Issue
Block a user