mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-19 21:38:30 +08:00
Merge pull request #57 from ThrowTheSwitch/bug/encoding
Support different encoding styles and force to something we can work with
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
$QUICK_RUBY_VERSION = RUBY_VERSION.split('.').inject(0){|vv,v| vv * 100 + v.to_i }
|
||||
File.expand_path(File.join(File.dirname(__FILE__),'colour_prompt'))
|
||||
|
||||
class UnityTestRunnerGenerator
|
||||
@ -38,11 +39,11 @@ class UnityTestRunnerGenerator
|
||||
module_name = File.basename(input_file)
|
||||
|
||||
#pull required data from source file
|
||||
File.open(input_file, 'r') do |input|
|
||||
tests = find_tests(input)
|
||||
testfile_includes = find_includes(input)
|
||||
source = File.read(input_file)
|
||||
source = source.force_encoding("ISO-8859-1").encode("utf-8", replace: nil) if ($QUICK_RUBY_VERSION > 10900)
|
||||
tests = find_tests(source)
|
||||
testfile_includes = find_includes(source)
|
||||
used_mocks = find_mocks(testfile_includes)
|
||||
end
|
||||
|
||||
#build runner file
|
||||
generate(input_file, output_file, tests, used_mocks, testfile_includes)
|
||||
@ -65,14 +66,12 @@ class UnityTestRunnerGenerator
|
||||
end
|
||||
end
|
||||
|
||||
def find_tests(input_file)
|
||||
def find_tests(source)
|
||||
tests_raw = []
|
||||
tests_args = []
|
||||
tests_and_line_numbers = []
|
||||
|
||||
input_file.rewind
|
||||
source_raw = input_file.read
|
||||
source_scrubbed = source_raw.gsub(/\/\/.*$/, '') # remove line comments
|
||||
source_scrubbed = source.gsub(/\/\/.*$/, '') # remove line comments
|
||||
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
||||
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
||||
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
|
||||
@ -94,7 +93,7 @@ class UnityTestRunnerGenerator
|
||||
end
|
||||
|
||||
#determine line numbers and create tests to run
|
||||
source_lines = source_raw.split("\n")
|
||||
source_lines = source.split("\n")
|
||||
source_index = 0;
|
||||
tests_and_line_numbers.size.times do |i|
|
||||
source_lines[source_index..-1].each_with_index do |line, index|
|
||||
@ -109,11 +108,7 @@ class UnityTestRunnerGenerator
|
||||
return tests_and_line_numbers
|
||||
end
|
||||
|
||||
def find_includes(input_file)
|
||||
input_file.rewind
|
||||
|
||||
#read in file
|
||||
source = input_file.read
|
||||
def find_includes(source)
|
||||
|
||||
#remove comments (block and line, in three steps to ensure correct precedence)
|
||||
source.gsub!(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
|
||||
|
Reference in New Issue
Block a user