File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,36 +161,17 @@ module Prism
161161 unicode_lists ( found ) if found == Encoding ::UTF_8 || found == Encoding ::UTF8_MAC
162162 end
163163
164- # bin/prism error [name] [ source]
164+ # bin/prism error [source]
165165 def error ( argv )
166- name = argv . shift
167-
168- source = nil
169- filepath = File . expand_path ( "../test/prism/errors/#{ name } .txt" , __dir__ )
166+ source , filepath = read_source ( argv )
167+ result = Prism . parse ( source )
170168
171- if argv . empty?
172- raise "Expected #{ filepath } to exist" unless File . file? ( filepath )
173169
174- source = File . read ( filepath , binmode : true , external_encoding : Encoding :: UTF_8 )
175- source = source . lines . grep_v ( /^ \s * \^ / ) . join . gsub ( / \n * \z / , "" )
170+ if result . errors . any?
171+ puts result . errors_format
176172 else
177- if File . file? ( filepath )
178- counter = 1
179-
180- begin
181- current = "#{ File . dirname ( filepath ) } /#{ File . basename ( filepath , ".txt" ) } _#{ counter += 1 } .txt"
182- end while File . file? ( current )
183-
184- filepath = current
185- end
186-
187- source , _ = read_source ( argv )
173+ puts "No syntax errors for #{ filepath } "
188174 end
189-
190- result = Prism . parse ( source )
191- raise "Expected #{ source . inspect } to have errors" if result . success?
192-
193- File . write ( filepath , result . errors_format )
194175 end
195176
196177 # bin/prism lex [source]
Original file line number Diff line number Diff line change 77module Prism
88 class ErrorsTest < TestCase
99 base = File . expand_path ( "errors" , __dir__ )
10- filepaths = Dir [ " **/*.txt", base : base ]
10+ filepaths = Dir [ ENV . fetch ( "FOCUS" , " **/*.txt") , base : base ]
1111
1212 filepaths . each do |filepath |
1313 ruby_versions_for ( filepath ) . each do |version |
@@ -100,6 +100,10 @@ def assert_errors(filepath, version)
100100 refute_empty errors , "Expected errors in #{ filepath } "
101101
102102 actual = result . errors_format
103+ if expected != actual && ENV [ "UPDATE_SNAPSHOTS" ]
104+ File . write ( filepath , actual )
105+ end
106+
103107 assert_equal expected , actual , "Expected errors to match for #{ filepath } "
104108 end
105109 end
You can’t perform that action at this time.
0 commit comments