11# frozen_string_literal: true
22
33require_relative "test_helper"
4+ require "securerandom"
45
56module SyntaxTree
67 class CLITest < Minitest ::Test
@@ -142,9 +143,8 @@ def test_generic_error
142143
143144 def test_plugins
144145 with_plugin_directory do |directory |
145- directory . plugin ( "plugin" , "puts 'Hello, world!'" )
146-
147- result = run_cli ( "format" , "--plugins=plugin" )
146+ plugin = directory . plugin ( "puts 'Hello, world!'" )
147+ result = run_cli ( "format" , "--plugins=#{ plugin } " )
148148
149149 assert_equal ( "Hello, world!\n test\n " , result . stdio )
150150 end
@@ -166,15 +166,14 @@ def test_language_server
166166 end
167167
168168 def test_config_file
169- config = <<~TXT
170- --print-width=100
171- --plugins=plugin
172- TXT
173-
174- with_config_file ( config ) do
175- with_plugin_directory do |directory |
176- directory . plugin ( "plugin" , "puts 'Hello, world!'" )
169+ with_plugin_directory do |directory |
170+ plugin = directory . plugin ( "puts 'Hello, world!'" )
171+ config = <<~TXT
172+ --print-width=100
173+ --plugins=#{ plugin }
174+ TXT
177175
176+ with_config_file ( config ) do
178177 contents = "#{ "a" * 40 } + #{ "b" * 40 } \n "
179178 result = run_cli ( "format" , contents : contents )
180179
@@ -201,12 +200,12 @@ def test_print_width_args_with_config_file_override
201200 end
202201
203202 def test_plugin_args_with_config_file
204- with_config_file ( "--plugins=hello" ) do
205- with_plugin_directory do |directory |
206- directory . plugin ( "hello" , "puts 'Hello, world!'" )
207- directory . plugin ( "goodbye" , "puts 'Bye, world!'" )
203+ with_plugin_directory do |directory |
204+ plugin1 = directory . plugin ( "puts 'Hello, world!'" )
208205
209- result = run_cli ( "format" , "--plugins=goodbye" )
206+ with_config_file ( "--plugins=#{ plugin1 } " ) do
207+ plugin2 = directory . plugin ( "puts 'Bye, world!'" )
208+ result = run_cli ( "format" , "--plugins=#{ plugin2 } " )
210209
211210 assert_equal ( "Hello, world!\n Bye, world!\n test\n " , result . stdio )
212211 end
@@ -258,8 +257,10 @@ def initialize(directory)
258257 @directory = directory
259258 end
260259
261- def plugin ( name , contents )
260+ def plugin ( contents )
261+ name = SecureRandom . hex
262262 File . write ( File . join ( directory , "#{ name } .rb" ) , contents )
263+ name
263264 end
264265 end
265266
0 commit comments