-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alexandre Terrasa <[email protected]>
- Loading branch information
Showing
3 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "tapioca/helpers/test/template" | ||
|
||
module Tapioca | ||
class BackwardsCompatibilitySpec < SpecWithProject | ||
GENERIC_INTERFACE_RB = <<~RB | ||
module GenericInterface | ||
extend T::Generic | ||
interface! | ||
Parameter = type_member | ||
end | ||
class Concrete | ||
extend T::Generic | ||
include GenericInterface | ||
Parameter = type_member | ||
end | ||
GENERIC_CONSTANT = T.let( | ||
Concrete.new, | ||
GenericInterface[Numeric] | ||
) | ||
RB | ||
|
||
describe "compilation of constants of generic types" do | ||
before do | ||
@expected_out = <<~OUT | ||
Compiled generic_interface | ||
create sorbet/rbi/gems/[email protected] | ||
OUT | ||
|
||
@expected_rbi = <<~RBI | ||
# typed: true | ||
# DO NOT EDIT MANUALLY | ||
# This is an autogenerated file for types exported from the `generic_interface` gem. | ||
# Please instead update this file by running `bin/tapioca gem generic_interface`. | ||
class Concrete | ||
extend T::Generic | ||
include ::GenericInterface | ||
Parameter = type_member | ||
end | ||
GENERIC_CONSTANT = T.let(T.unsafe(nil), Concrete[T.untyped]) | ||
module GenericInterface | ||
extend T::Generic | ||
interface! | ||
Parameter = type_member | ||
end | ||
RBI | ||
|
||
@generic_interface = mock_gem("generic_interface", "0.0.1") do | ||
write("lib/generic_interface.rb", GENERIC_INTERFACE_RB) | ||
end | ||
@project = mock_project(sorbet_dependency: false) | ||
@project.require_mock_gem(@generic_interface) | ||
end | ||
|
||
after do | ||
@project.destroy | ||
end | ||
|
||
it "must succeed on sorbet-runtime < 0.5.10554" do | ||
@project.require_real_gem("sorbet-static-and-runtime", "=0.5.10539") | ||
@project.bundle_install | ||
result = @project.tapioca("gem", true) | ||
|
||
assert_stdout_includes(result, @expected_out) | ||
assert_project_file_equal("sorbet/rbi/gems/[email protected]", @expected_rbi) | ||
assert_empty_stderr(result) | ||
assert_success_status(result) | ||
end | ||
|
||
it "must succeed on sorbet-runtime >= 0.5.10554" do | ||
@project.require_real_gem("sorbet-static-and-runtime", ">=0.5.10554") | ||
@project.bundle_install | ||
result = @project.tapioca("gem", true) | ||
|
||
assert_stdout_includes(result, @expected_out) | ||
assert_project_file_equal("sorbet/rbi/gems/[email protected]", @expected_rbi) | ||
assert_empty_stderr(result) | ||
assert_success_status(result) | ||
end | ||
end | ||
end | ||
end |