Skip to content

Commit

Permalink
Add parser round trip test to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Feb 5, 2022
1 parent dd10945 commit ab1b234
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ jobs:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- run: bundle exec bin/corpus
ruby-integration-spec:
name: Parser Round Trip Tests
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.6, ruby-2.7, ruby-3.0]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- run: bundle exec ruby bin/parser-round-trip-test
ruby-rubocop:
name: Rubocop
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Fix emit of of `match_pattern` vs `match_pattern_p`

[#298](https://github.com/mbj/unparser/pull/298)

* Add round trip tests dynamically derived from the `parser` gems test suite to CI

# v0.6.3 2022-01-16

[#290](https://github.com/mbj/unparser/pull/290)
Expand Down
10 changes: 6 additions & 4 deletions test/run-parser-tests.rb → bin/parser-round-trip-test
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'unparser'

$: << __dir__
$: << Pathname.new(__dir__).parent.join('test')

testBuilder = Class.new(Parser::Builders::Default)
testBuilder.modernize
Expand All @@ -26,8 +28,6 @@ class Test
:rubies
)

TARGET_RUBIES = %w[2.6 2.7]

EXPECT_FAILURE = {}.freeze

def legacy_attributes
Expand Down Expand Up @@ -56,7 +56,7 @@ def expect_failure?
end

def allow_ruby?
rubies.empty? || rubies.any?(TARGET_RUBIES.method(:include?))
rubies.empty? || rubies.include?(RUBY_VERSION)
end

def right(value)
Expand All @@ -65,7 +65,9 @@ def right(value)

def validation
identification = name.to_s

generated_source = Unparser.unparse_either(node)
.fmap { |string| string.dup.force_encoding(parser_source.encoding).freeze }

generated_node = generated_source.lmap{ |_value| }.bind do |source|
parse_either(source, identification)
Expand Down

0 comments on commit ab1b234

Please sign in to comment.