Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/gems/gems/bad_example-100/lib/bad_example/basic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo = nil
true if @foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eval "def foo; end"
def foo; end
19 changes: 19 additions & 0 deletions test/gems/specifications/bad_example-100.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- encoding: utf-8 -*-
# stub: bad_example 100 ruby lib

Gem::Specification.new do |s|
s.name = "bad_example"
s.version = "100"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Semyon Perepelitsa"]
s.date = "2015-05-18"
s.email = "sema@sema.in"
s.homepage = "https://github.com/semaperepelitsa/ruby_warning_filter"
s.licenses = ["MIT"]
s.rubygems_version = "2.4.5"
s.summary = "***"

s.installed_by_version = "2.4.5" if s.respond_to? :installed_by_version
end
63 changes: 63 additions & 0 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "minitest/autorun"
require "tempfile"

class IntegrationTest < Minitest::Test
GEM_PATH = File.expand_path("#{__dir__}/gems")
GEM_PREFIX = File.join(GEM_PATH, "gems/bad_example-100/lib/bad_example")

LIB = File.expand_path("#{__dir__}/../lib")
CODE = <<-RUBY.gsub("\n", "; ")
$VERBOSE = true
require "ruby_warning_filter"
$stderr = RubyWarningFilter.new($stderr)
RUBY

def test_custom
assert_equal "Custom warning\n",
ruby(CODE, 'warn "Custom warning"')
end

def test_internal
assert_equal "-e:2: warning: instance variable @foo not initialized\n",
ruby(CODE, 'true if @foo')
end

def test_external_non_filtered
assert_equal <<-END, ruby('require "bad_example/basic"')
#{GEM_PREFIX}/basic.rb:1: warning: assigned but unused variable - foo
#{GEM_PREFIX}/basic.rb:2: warning: instance variable @foo not initialized
END
end

def test_external
assert_equal "", ruby(CODE, 'require "bad_example/basic"')
end

def test_eval_redefined_non_filtered
assert_equal <<-END, ruby('require "bad_example/eval_redefined"')
#{GEM_PREFIX}/eval_redefined.rb:2: warning: method redefined; discarding old foo
(eval):1: warning: previous definition of foo was here
END
end

def test_eval_redefined
assert_equal "", ruby(CODE, 'require "bad_example/eval_redefined"')
end

def test_with_backtrace
skip "Pending"
end

def ruby(*lines)
IO.pipe do |rd, wr|
success = system({ "GEM_PATH" => GEM_PATH }, "ruby", "-w", "-I", LIB, "-e", lines.join("\n"), :err => wr, unsetenv_others: true)
wr.close
out = rd.read
if success
out
else
raise out
end
end
end
end