From b5e121f304a96a25184a873dce74b6842715e2e4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 6 Jun 2023 15:28:50 +0900 Subject: [PATCH] Embed racc/info.rb too --- Rakefile | 8 +++++++- test/test_parser_text.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/test_parser_text.rb diff --git a/Rakefile b/Rakefile index 7f3272e1..d98d8355 100644 --- a/Rakefile +++ b/Rakefile @@ -39,11 +39,17 @@ end file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t| source = 'lib/racc/parser.rb' + text = File.read(source) + text.gsub!(/^require '(.*)'$/) do + %[unless $".find {|p| p.end_with?('/#$1.rb')}\n$".push '#$1.rb'\n#{File.read("lib/#{$1}.rb")}\nend\n] + rescue + $& + end open(t.name, 'wb') { |io| io.write(<<-eorb) module Racc PARSER_TEXT = <<'__end_of_file__' -#{File.read(source)} +#{text} __end_of_file__ end eorb diff --git a/test/test_parser_text.rb b/test/test_parser_text.rb new file mode 100644 index 00000000..22790bd7 --- /dev/null +++ b/test/test_parser_text.rb @@ -0,0 +1,10 @@ +require File.expand_path(File.join(__dir__, 'case')) + +module Racc + class TestRaccParserText < TestCase + def test_parser_text_require + assert_not_match(/^require/, Racc::PARSER_TEXT) + ruby "-I#{LIB_DIR}", "-rracc/parser-text", %[-e$:.clear], %[-eeval(Racc::PARSER_TEXT)] + end + end +end