steep 0.16.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +6 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep/project/file.rb +1 -1
  9. data/lib/steep/project/hover_content.rb +1 -1
  10. data/lib/steep/server/code_worker.rb +1 -1
  11. data/lib/steep/server/signature_worker.rb +4 -4
  12. data/lib/steep/type_construction.rb +10 -16
  13. data/lib/steep/type_inference/constant_env.rb +2 -10
  14. data/lib/steep/type_inference/context.rb +1 -0
  15. data/lib/steep/version.rb +1 -1
  16. data/steep.gemspec +1 -5
  17. metadata +17 -135
  18. data/exe/rbs +0 -3
  19. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  20. data/vendor/ruby-signature/.gitignore +0 -12
  21. data/vendor/ruby-signature/.rubocop.yml +0 -15
  22. data/vendor/ruby-signature/BSDL +0 -22
  23. data/vendor/ruby-signature/COPYING +0 -56
  24. data/vendor/ruby-signature/Gemfile +0 -6
  25. data/vendor/ruby-signature/README.md +0 -93
  26. data/vendor/ruby-signature/Rakefile +0 -142
  27. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  28. data/vendor/ruby-signature/bin/console +0 -14
  29. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  30. data/vendor/ruby-signature/bin/setup +0 -10
  31. data/vendor/ruby-signature/bin/sort +0 -89
  32. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  33. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  34. data/vendor/ruby-signature/docs/sigs.md +0 -148
  35. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  36. data/vendor/ruby-signature/docs/syntax.md +0 -528
  37. data/vendor/ruby-signature/exe/rbs +0 -7
  38. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  39. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  40. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  41. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  42. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  43. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  44. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  45. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  46. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  47. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  48. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  49. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  50. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  51. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  52. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  53. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  54. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  55. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  56. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  57. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  58. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  59. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  60. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  61. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  62. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  63. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  64. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  65. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  66. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  67. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  68. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  69. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  70. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  71. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  72. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  73. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  74. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  75. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  76. data/vendor/ruby-signature/rbs.gemspec +0 -46
  77. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  78. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  79. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  80. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  81. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  82. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  83. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
  84. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  85. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  86. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  87. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  88. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  89. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  90. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  91. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  92. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  93. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  94. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  95. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  96. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  97. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  98. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  99. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  100. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  101. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  102. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  103. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  104. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  105. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  106. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  107. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  108. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  109. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  110. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  111. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  112. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  113. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  114. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  115. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  116. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  117. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  118. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  119. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  120. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  121. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  122. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  123. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  124. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  125. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  126. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  127. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  128. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  129. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  130. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  131. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  132. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  133. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  134. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  135. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  136. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  137. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  138. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  139. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  140. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  141. data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
  142. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  143. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  144. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  145. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  146. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  147. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rdoc"
4
-
5
- def store_for_class(name, stores:)
6
- stores.find do |store|
7
- store.find_class_named(name) || store.find_module_named(name)
8
- end
9
- end
10
-
11
- def format_comment(comment)
12
- out = RDoc::Markup::Document.new
13
- out << comment
14
- formatter = RDoc::Markup::ToMarkdown.new
15
- out.accept(formatter)
16
- end
17
-
18
- def comment_for_constant(name, stores:)
19
- *class_components, const_name = name.split(/::/)
20
- class_name = class_components.join("::")
21
-
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- constant = klass.constants.find do |const|
27
- const.name == const_name
28
- end
29
-
30
- if constant&.documented?
31
- format_comment(constant.comment)
32
- end
33
- end
34
-
35
- def comment_for_class(class_name, stores:)
36
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
37
- store.find_class_named(class_name) || store.find_module_named(class_name)
38
- }
39
-
40
- if klass&.documented?
41
- format_comment(klass.comment)
42
- end
43
- end
44
-
45
- def comment_for_method(klass, method, stores:)
46
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
47
-
48
- if method&.documented?
49
- out = RDoc::Markup::Document.new
50
-
51
- out << method.comment
52
-
53
- if method.arglists
54
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
55
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
56
- out << RDoc::Markup::Verbatim.new(*arglists)
57
- end
58
-
59
- out.accept(RDoc::Markup::ToMarkdown.new)
60
- end
61
- rescue RDoc::Store::MissingFileError
62
- nil
63
- end
64
-
65
- if ARGV.empty?
66
- puts 'query-rdoc [subject]'
67
- puts " subject ::= ClassName (class, module, or constant)"
68
- puts " | ClassName.method (singleton method)"
69
- puts " | ClassName#method (instance method)"
70
- exit
71
- end
72
-
73
- stores = []
74
- RDoc::RI::Paths.each true, true, false, false do |path, type|
75
- STDERR.puts "Loading store from #{path}..."
76
- store = RDoc::RI::Store.new(path, type)
77
- store.load_all
78
- stores << store
79
- end
80
-
81
- subject = ARGV[0]
82
-
83
- case
84
- when match = subject.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
85
- STDERR.puts "Finding instance method #{match[:constant_name]} # #{match[:method_name]} ..."
86
- comment = comment_for_method(match[:constant_name], "##{match[:method_name]}", stores: stores)
87
- when match = subject.match(/(?<constant_name>[^.]+)\.(?<method_name>.+)/)
88
- STDERR.puts "Finding singleton method #{match[:constant_name]} . #{match[:method_name]} ..."
89
- comment = comment_for_method(match[:constant_name], "::#{match[:method_name]}", stores: stores)
90
- else
91
- STDERR.puts "Finding class/module/constant #{subject} ..."
92
- comment = comment_for_class(subject, stores: stores) || comment_for_constant(subject, stores: stores)
93
- end
94
-
95
- if comment
96
- STDERR.puts "Printing document..."
97
- comment.each_line do |line|
98
- puts "# #{line}"
99
- end
100
- else
101
- STDERR.puts "Nothing to print; failed to query the document..."
102
- exit 1
103
- end
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
9
-
10
- bundle exec rake parser
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
-
6
- Members = RBS::AST::Members
7
-
8
- def group(member)
9
- case member
10
- when Members::Include, Members::Extend, Members::Prepend
11
- 0
12
- when Members::ClassVariable
13
- -3
14
- when Members::ClassInstanceVariable
15
- -2
16
- when Members::InstanceVariable
17
- -1
18
- when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
19
- 2
20
- when Members::MethodDefinition
21
- if member.singleton?
22
- if member.name == :new
23
- 0.4
24
- else
25
- 1
26
- end
27
- else
28
- if member.name == :initialize
29
- 0.5
30
- else
31
- 3
32
- end
33
- end
34
- when Members::Alias
35
- if member.singleton?
36
- 1
37
- else
38
- 3
39
- end
40
- when Members::Private, Members::Public
41
- -4
42
- end
43
- end
44
-
45
- def key(member)
46
- case member
47
- when Members::Include, Members::Extend, Members::Prepend
48
- member.name.to_s
49
- when Members::ClassVariable, Members::ClassInstanceVariable, Members::InstanceVariable
50
- member.name.to_s
51
- when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
52
- member.name.to_s
53
- when Members::MethodDefinition
54
- member.name.to_s
55
- when Members::Alias
56
- member.new_name.to_s
57
- else
58
- 1
59
- end
60
- end
61
-
62
- ARGV.map {|f| Pathname(f) }.each do |path|
63
- puts "Opening #{path}..."
64
-
65
- buffer = RBS::Buffer.new(name: path, content: path.read)
66
- sigs = RBS::Parser.parse_signature(buffer)
67
-
68
- sigs.each do |sig|
69
- case sig
70
- when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module, RBS::AST::Declarations::Interface
71
- sig.members.sort! do |m1, m2|
72
- group1 = group(m1)
73
- group2 = group(m2)
74
-
75
- if group1 == group2
76
- key(m1) <=> key(m2)
77
- else
78
- group1 <=> group2
79
- end
80
- end
81
- end
82
- end
83
-
84
- puts "Writing #{path}..."
85
- path.open('w') do |out|
86
- writer = RBS::Writer.new(out: out)
87
- writer.write sigs
88
- end
89
- end
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- RUBY_27 = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
4
- Gem::Version.new('2.7.0') <= ruby_version && ruby_version < Gem::Version.new("2.8.0")
5
- end
6
-
7
- unless RUBY_27
8
- STDERR.puts "🚨🚨🚨 stdlib test requires Ruby 2.7 but RUBY_VERSION==#{RUBY_VERSION}, exiting... 🚨🚨🚨"
9
- exit
10
- end
11
-
12
- require "pathname"
13
-
14
- ARGV.each do |arg|
15
- load arg
16
- end
@@ -1,97 +0,0 @@
1
- # Standard Library Signatures Contribution Guide
2
-
3
- ## Guides
4
-
5
- * [Stdlib Signatures Guide](stdlib.md)
6
- * [Syntax](syntax.md)
7
- * [Writing Signature Guide](sigs.md)
8
-
9
- ## Steps for Contribution
10
-
11
- 1. Pick the class/library you will work for.
12
- 2. Assign yourself on the [work spreadsheet](https://docs.google.com/spreadsheets/d/199rRB93I16H0k4TGZS3EGojns2R0W1oCsN8UPJzOpyU/edit#gid=1383307992) (optional but recommended to avoid duplication).
13
- 3. Sort RBS members (if there is RBS files for the classes).
14
- - Use `bin/sort stdlib/path/to/signature.rbs` command and confirm it does not break definitions.
15
- - Committing the sorted RBSs is recommended.
16
- 4. Add method prototypes.
17
- - Use `rbs prototype runtime --merge CLASS_NAME` command to generate the missing method definitions.
18
- - Committing the auto generated signatures is recommended.
19
- 5. Annotate with RDoc.
20
- - Use `bin/annotate-with-rdoc stdlib/path/to/signature.rbs` to annotate the RBS files.
21
- - Committing the generated annotations is recommended.
22
- 6. Fix method types and comments.
23
- - The auto generated RDoc comments include `arglists` section, which we don't expect to be included the RBS files.
24
- - Delete the `arglists` sections.
25
- - Give methods correct types.
26
- - Write tests, if possible. (If it is too difficult to write test, skip it.)
27
-
28
- ## The Target Version
29
-
30
- * The standard library signatures targets Ruby 2.7 for now.
31
- * The library code targets Ruby 2.6, 2.7, and 3.0.
32
-
33
- ## Stdlib Worksheet
34
-
35
- You can find the list of classes/libraries:
36
-
37
- * https://docs.google.com/spreadsheets/d/199rRB93I16H0k4TGZS3EGojns2R0W1oCsN8UPJzOpyU/edit#gid=1383307992
38
-
39
- Assign yourself when you start working for a class or library.
40
- After reviewing and merging your pull request, I will update the status of the library.
41
-
42
- You may find the *Good for first contributor* column where you can find some classes are recommended for new contributors (👍), and some classes are not-recommended (👎).
43
-
44
- ## Useful Tools
45
-
46
- * `rbs prototype runtime --merge String`
47
- * Generate a prototype using runtime API.
48
- * `--merge` tells to use the method types in RBS if exists.
49
- * `rbs prototype runtime --merge --method-owner=Numeric Integer`
50
- * You can use --method-owner if you want to print method of other classes too, for documentation purpose.
51
- * `bin/annotate-with-rdoc stdlib/builtin/string.rbs`
52
- * Write comments using RDoc.
53
- * It contains arglists section, but I don't think we should have it in RBS files.
54
- * `bin/query-rdoc String#initialize`
55
- * Print RDoc documents in the format you can copy-and-paste to RBS.
56
- * `bin/sort stdlib/builtin/string.rbs`
57
- * Sort declarations members in RBS files.
58
- * `rbs validate -r LIB`
59
- Validate the syntax and some of the semantics.
60
- * `rake generate:stdlib_test[String]`
61
- Scaffold the stdlib test.
62
-
63
- ## Standard STDLIB Members Order
64
-
65
- We define the standard members order so that ordering doesn't bother reading diffs or git-annotate outputs.
66
-
67
- 1. `def self.new` or `def initialize`
68
- 2. Mixins
69
- 3. Attributes
70
- 4. Singleton methods
71
- 5. `public` & public instance methods
72
- 6. `private` & private instance methods
73
-
74
- ```
75
- class HelloWorld[X]
76
- def self.new: [A] () { (void) -> A } -> HelloWorld[A] # new or initialize comes first
77
- def initialize: () -> void
78
-
79
- include Enumerable[X, void] # Mixin comes next
80
-
81
- attr_reader language: (:ja | :en) # Attributes
82
-
83
- def self.all_languages: () -> Array[Symbol] # Singleton methods
84
-
85
- public # Public instance methods
86
-
87
- def each: () { (A) -> void } -> void # Members are sorted dicionary order
88
-
89
- def to_s: (?Locale) -> String
90
-
91
- private # Private instance methods
92
-
93
- alias validate validate_locale
94
-
95
- def validate_locale: () -> void
96
- end
97
- ```
@@ -1,148 +0,0 @@
1
- # Writing Signatures Guide
2
-
3
- You can write the signature of your applications and libraries.
4
- Signature of your Ruby program would help:
5
-
6
- 1. Understanding the code structure
7
- 2. Finding APIs
8
-
9
- And if you ship your gem with signature, the gem users can type check their applications!
10
-
11
- ## Writing signatures
12
-
13
- You first need to write your program's signature.
14
- See [syntax guide](syntax.md).
15
-
16
- ## Testing signatures
17
-
18
- When you finish writing signature, you may want to test the signature.
19
- ruby-signature provides a feature to test your signature.
20
-
21
- ```
22
- $ RBS_TEST_TARGET='Foo::*' bundle exec ruby -r rbs/test/setup test/foo_test.rb
23
- ```
24
-
25
- The test installs instrumentations to spy the method calls and check if arguments/return values are correct with respect to the type of the method in signature.
26
- If errors are reported by the test, you will fix the signature.
27
- You will be sure that you ship a correct signature finally.
28
-
29
- The instrumentations are implemneted using `Module#prepend`.
30
- It defines a module with same name of methods, which asserts the type of arguments/return values and calls `super`.
31
-
32
- ## Type errors
33
-
34
- If the test detects type errors, it will print error messages.
35
-
36
- ### ArgumentTypeError, BlockArgumentTypeError
37
-
38
- The message means there is an unexpected type of argument or block argument.
39
-
40
- ```
41
- ERROR -- : [Kaigi::Speaker.new] ArgumentTypeError: expected `::String` (email) but given `:"matsumoto@soutaro.com"`
42
- ```
43
-
44
- ### ArgumentError, BlockArgumentError
45
-
46
- The message means there is an unexpected argument or missing argument.
47
-
48
- ```
49
- [Kaigi::Speaker.new] ArgumentError: expected method type (size: ::Symbol, email: ::String, name: ::String) -> ::Kaigi::Speaker
50
- ```
51
-
52
- ### ReturnTypeError, BlockReturnTypeError
53
-
54
- The message means the return value from method or block is incorrect.
55
-
56
- ```
57
- ERROR -- : [Kaigi::Conference#each_speaker] ReturnTypeError: expected `self` but returns `[#<Kaigi::Speaker:0x00007fb2b249e5a0 @name="Soutaro Matsumoto", @email=:"matsumoto@soutaro.com">]`
58
- ```
59
-
60
- ### UnexpectedBlockError, MissingBlockError
61
-
62
- The errors are reported when required block is not given or unused block is given.
63
-
64
- ```
65
- ERROR -- : [Kaigi::Conference#speakers] UnexpectedBlockError: unexpected block is given for `() -> ::Array[::Kaigi::Speaker]`
66
- ```
67
-
68
- ### UnresolvedOverloadingError
69
-
70
- The error means there is a type error on overloaded methods.
71
- The `ruby-signature` test framework tries to the best error message for overloaded methods too, but it reports the `UnresolvedOverloadingError` when it fails.
72
-
73
- ## Setting up the test
74
-
75
- The design of the signature testing aims to be non-intrusive. The setup is done in two steps:
76
-
77
- 1. Loading the testing library
78
- 2. Setting up the test through environment variables
79
-
80
- ### Loading the library
81
-
82
- You need to require `rbs/test/setup` for signature testing.
83
- You can do it using `-r` option through command line argument or the `RUBYOPT` environment variable.
84
-
85
- ```
86
- $ ruby -r rbs/test/setup run_tests.rb
87
- $ RUBYOPT='-rruby/signature/test/setup' rake test
88
- ```
89
-
90
- When you are using Bundler, you may need to require `bundler/setup` explicitly.
91
-
92
- ```
93
- $ RUBYOPT='-rbundler/setup -rruby/signature/test/setup' bundle exec rake test
94
- ```
95
-
96
- ### Environment variables
97
-
98
- You need to specify `RBS_TEST_TARGET` to run the test, and you can customize the test with the following environment variables.
99
-
100
- - `RBS_TEST_SKIP` (optional)
101
- - `RBS_TEST_OPT` (optional)
102
- - `RBS_TEST_LOGLEVEL` (optional)
103
- - `RBS_TEST_RAISE` (optional)
104
-
105
- `RBS_TEST_TARGET` is to specify the classes you want to test. `RBS_TEST_TARGET` can contain comma-separated class name pattern, which is one of an exact class name or with wildcard `*`.
106
-
107
- - `RBS_TEST_TARGET=Foo::Bar,Foo::Baz` comma separated exact class names
108
- - `RBS_TEST_TARGET=Foo::*` using wildcard
109
-
110
- `RBS_TEST_SKIP` is to skip some of the classes which matches with `RBS_TEST_TARGET`.
111
-
112
- `RBS_TEST_OPT` is to pass the options for ruby signature handling.
113
- You may need to specify `-r` or `-I` to load signatures.
114
- The default is `-I sig`.
115
-
116
- ```
117
- RBS_TEST_OPT='-r set -r pathname -I sig'
118
- ```
119
-
120
- `RBS_TEST_LOGLEVEL` can be used to configure log level. Defaults to `info`.
121
-
122
- `RBS_TEST_RAISE` may help to debug the type signatures.
123
- If the environment variable is set, it raises an exception when a type error is detected.
124
- You can see the backtrace how the type error is caused and debug your program or signature.
125
-
126
- So, a typical command line to start the test would look like the following:
127
-
128
- ```
129
- $ RBS_TEST_LOGLEVEL=error \
130
- RBS_TEST_TARGET='Kaigi::*' \
131
- RBS_TEST_SKIP='Kaigi::MonkeyPatch' \
132
- RBS_TEST_OPT='-rset -rpathname -Isig -Iprivate' \
133
- RBS_TEST_RAISE=true \
134
- RUBYOPT='-rbundler/setup -rruby/signature/test/setup' \
135
- bundle exec rake test
136
- ```
137
-
138
- ## Testing tips
139
-
140
- ### Skipping a method
141
-
142
- You can skip installing the instrumentation per-method basis using `rbs:test:skip` annotation.
143
-
144
- ```
145
- class String
146
- %a{rbs:test:skip} def =~: (Regexp) -> Integer?
147
- end
148
- ```