rspec / rspec-core

RSpec runner and formatters
http://rspec.info
MIT License
1.22k stars 762 forks source link

Windows doesn't support chinese sample #2660

Open WoolenWang opened 5 years ago

WoolenWang commented 5 years ago
Run options: include {:full_description=>/AGENT::Services::CLI\ �첽������\��python������Ŀ����/}
    from D:/tools/atr/sft_tool/mingw32/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.1/lib/rspec/core/world.rb:182:in `announce_filters'
    from D:/tools/atr/sft_tool/mingw32/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.1/lib/rspec/core/runner.rb:99:in `setup'
    from D:/tools/atr/sft_tool/mingw32/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.1/lib/rspec/core/runner.rb:86:in `run'
    from D:/tools/atr/sft_tool/mingw32/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.1/lib/rspec/core/runner.rb:71:in `run'
    from D:/tools/atr/sft_tool/mingw32/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.1/lib/rspec/core/runner.rb:45:in `invoke'
    from D:/tools/atr/sft_tool/mingw32/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.1/exe/rspec:4:in `<top (required)>'
    from D:/tools/atr/sft_tool/mingw32/bin/rspec:23:in `load'
    from D:/tools/atr/sft_tool/mingw32/bin/rspec:23:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'
JonRowe commented 5 years ago

:wave: Can you explain your problem in more detail? What are you trying to achieve thats causing this?

WoolenWang commented 5 years ago

when using rspec to test a test case in UTF-8 chinese name like:

describe AATM::Build::Mapper do
  describe '将 嵌套哈希数据 转换为 树结构' do
    it '空测试套' do
       pus "test"
    end
  end
end

in this code with windows using cmd:

 rspec D:/git/auto-agent/spec/build/mapper_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter --example "AATM::Build::Mapper 将 嵌套哈希数据 转换为 树结构 空测试套"

with rubymine ide will get the error above

benoittgt commented 5 years ago

I don't have a windows machine at the moment but this reproduction script might help us:

begin
  require "bundler/inline"
rescue LoadError => e
  raise e
end

gemfile(true) do
  source "https://rubygems.org"

  gem "rspec"
  gem "rspec-teamcity"
end

require 'rspec/autorun'

RSpec.configure do |c|
  c.add_formatter Spec::Runner::Formatter::TeamcityFormatter
  c.default_formatter = Spec::Runner::Formatter::TeamcityFormatter
end

RSpec.describe 'rspec/rspec/44' do
  describe '将 嵌套哈希数据 转换为 树结构' do
    it '空测试套' do
      puts "test"
    end
  end
end
WoolenWang commented 5 years ago

the key to this problem is not the name in the "describe " or the name in the "it '空测试套' do" the key is the params get in the params from the command line in windows

rspec D:/git/auto-agent/spec/build/mapper_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter --example "AATM::Build::Mapper 将 嵌套哈希数据 转换为 树结构 空测试套"

the chinese or other none english key name(in the --example) will transfer in the windows encoding (such as gb2312 in chinese or Shift_JIS in japan. ) and our code is in a wide used encoding "utf-8" this may be the problem.[which my code is work fine in linux with utf-8 encoding ]

and we can't change the windows encoding as we can do in linux.

the code you posted i have run in my windows env, is ok to pass.

Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Using bundler 1.16.0
Using diff-lcs 1.3
Using rspec-support 3.8.2
Using rspec-core 3.8.2
Using rspec-expectations 3.8.4
Using rspec-mocks 3.8.1
Using rspec 3.8.0
Using rspec-teamcity 1.0.0

##teamcity[enteredTheMatrix timestamp = '2019-07-29T20:22:40.021+0800']

##teamcity[testCount count = '1' timestamp = '2019-07-29T20:22:40.084+0800']

##teamcity[testSuiteStarted name = 'rspec/rspec/44' locationHint = 'file://D:/test.rb:22' timestamp = '2019-07-29T20:22:40.085+0800']

##teamcity[testSuiteStarted name = '将 嵌套哈希数据 转换为 树结构' locationHint = 'file://D:/test.rb:23' timestamp = '2019-07-29T20:22:40.085+0800']

##teamcity[testStarted name = '将 嵌套哈希数据 转换为 树结构 空测试套' captureStandardOutput = 'true' locationHint = 'file://D:/test.rb:24' timestamp = '2019-07-29T20:22:40.085+0800']
test

##teamcity[testFinished name = '将 嵌套哈希数据 转换为 树结构 空测试套' duration = '1564402960086' diagnosticInfo = 'rspec |[3.8.2|], f/s=(1564402960086, 0), duration=1564402960086, time.now=2019-07-29 20:22:40 +0800, raw|[:started_at|]=2019-07-29 20:22:40 +0800, raw|[:finished_at|]=2019-07-29 20:22:40 +0800, raw|[:run_time|]=0.000956' timestamp = '2019-07-29T20:22:40.086+0800']

##teamcity[testSuiteFinished name = '将 嵌套哈希数据 转换为 树结构' timestamp = '2019-07-29T20:22:40.086+0800']

##teamcity[testSuiteFinished name = 'rspec/rspec/44' timestamp = '2019-07-29T20:22:40.086+0800']

1 example, 0 failures, 1 passed

Finished in 0.003988 seconds

is that any chance the rspec will handle the command line encoding corrected and we as a user can ignore the difference in windows encoding and linux encoding.

benoittgt commented 4 years ago

I am wondering if this PR change can help you? https://github.com/rspec/rspec-core/pull/2575/files

Just to notice that it is still not fixed: https://github.com/rspec/rspec-core/issues/2543#issuecomment-446551666

pirj commented 4 years ago

@WoolenWang Can you figure out the difference between the code @benoittgt provided and yours to understand why yours fails and the script provided provides correct output?

A pull request that fails on AppVeyor would sure be very helpful.

I'll close the issue meanwhile, since otherwise it's not clear how to reproduce the problem and how to fix it. Please feel free to reopen.

JonRowe commented 4 years ago

The problem's pretty clear, Chinese string's being passed in from the command line on windows are not being parsed properly, the issue I, we, have is trying to replicate it to fix it, ideally we need a chinese person to help!