SlatherOrg / slather

Generate test coverage reports for Xcode projects & hook it into CI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash: undefined method `[]' for false:FalseClass - can't detect scheme from CLI

rogerluan opened this issue · comments

I found the following error:

Slathering...
undefined method `[]' for false:FalseClass

	Are you sure your project is generating coverage? Make sure you enable code coverage in the Test section of your Xcode scheme.
	Did you specify your Xcode scheme? (--scheme or 'scheme' in .slather.yml)
	If you're using a workspace, did you specify it? (--workspace or 'workspace' in .slather.yml)
	If you use a different Xcode configuration, did you specify it? (--configuration or 'configuration' in .slather.yml)
Click to see stacktrace

Traceback (most recent call last):
	24: from /Users/rogerluan/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
	23: from /Users/rogerluan/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
	22: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.2.17/exe/bundle:37:in `<top (required)>'
	21: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/friendly_errors.rb:130:in `with_friendly_errors'
	20: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.2.17/exe/bundle:49:in `block in <top (required)>'
	19: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:24:in `start'
	18: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	17: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:30:in `dispatch'
	16: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	15: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	14: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	13: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:494:in `exec'
	12: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
	11: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:63:in `kernel_load'
	10: from /Users/rogerluan/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:63:in `load'
	 9: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/bin/slather:23:in `<top (required)>'
	 8: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/bin/slather:23:in `load'
	 7: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/slather-2.7.1/bin/slather:17:in `<top (required)>'
	 6: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/clamp-1.3.2/lib/clamp/command.rb:140:in `run'
	 5: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
	 4: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/clamp-1.3.2/lib/clamp/subcommand/execution.rb:18:in `execute'
	 3: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
	 2: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/slather-2.7.1/lib/slather/command/coverage_command.rb:59:in `execute'
	 1: from /Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/slather-2.7.1/lib/slather/project.rb:324:in `configure'
/Users/rogerluan/Documents/Projects/iOS/.vendor/ruby/2.6.0/gems/slather-2.7.1/lib/slather/project.rb:398:in `configure_scheme': undefined method `[]' for false:FalseClass (NoMethodError)

When executing:

bundle exec slather coverage \
      --cobertura-xml \
      --scheme MyProject-Package \ 
      --source-directory Sources \
      --binary-basename MyProject \     
      --output-directory Generated \
      --ignore 'Tests/*' \
      MyProject.xcodeproj

As you can see in the stacktrace, the crash is here:

self.scheme ||= self.class.yml["scheme"] if self.class.yml["scheme"]

Apparently it's not picking up the --scheme argument correctly. I tried adding single and double quotes around the scheme value, with no luck.

But if I use a .slather.yml with a scheme, then everything works.

I did a quick code review but I couldn't spot the bug in the slather codebase

I just tested this in a project that has a workspace, and it detects the scheme correctly, via CLI.
The problematic project that I'm having issues with is a Swift Package (and I'm generating a xcodeproj using swift package generate-xcodeproj

Not sure if this helps the investigation 🤔