rbs 0.5.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/Gemfile +2 -0
  4. data/Rakefile +2 -3
  5. data/docs/stdlib.md +0 -2
  6. data/docs/syntax.md +6 -3
  7. data/goodcheck.yml +65 -0
  8. data/lib/rbs.rb +1 -0
  9. data/lib/rbs/ast/comment.rb +6 -0
  10. data/lib/rbs/ast/declarations.rb +44 -6
  11. data/lib/rbs/cli.rb +21 -3
  12. data/lib/rbs/constant_table.rb +1 -1
  13. data/lib/rbs/definition_builder.rb +290 -124
  14. data/lib/rbs/environment.rb +50 -37
  15. data/lib/rbs/errors.rb +68 -25
  16. data/lib/rbs/factory.rb +14 -0
  17. data/lib/rbs/location.rb +15 -0
  18. data/lib/rbs/parser.y +89 -28
  19. data/lib/rbs/prototype/rb.rb +2 -2
  20. data/lib/rbs/prototype/rbi.rb +1 -1
  21. data/lib/rbs/prototype/runtime.rb +1 -1
  22. data/lib/rbs/substitution.rb +6 -2
  23. data/lib/rbs/test.rb +82 -3
  24. data/lib/rbs/test/errors.rb +5 -1
  25. data/lib/rbs/test/hook.rb +133 -259
  26. data/lib/rbs/test/observer.rb +17 -0
  27. data/lib/rbs/test/setup.rb +37 -20
  28. data/lib/rbs/test/setup_helper.rb +29 -0
  29. data/lib/rbs/test/spy.rb +0 -321
  30. data/lib/rbs/test/tester.rb +118 -0
  31. data/lib/rbs/test/type_check.rb +42 -5
  32. data/lib/rbs/validator.rb +4 -0
  33. data/lib/rbs/version.rb +1 -1
  34. data/lib/rbs/writer.rb +2 -2
  35. data/schema/decls.json +21 -10
  36. data/stdlib/builtin/enumerable.rbs +2 -2
  37. data/stdlib/builtin/proc.rbs +1 -2
  38. data/stdlib/json/json.rbs +6 -0
  39. data/stdlib/logger/formatter.rbs +23 -0
  40. data/stdlib/logger/log_device.rbs +39 -0
  41. data/stdlib/logger/logger.rbs +507 -0
  42. data/stdlib/logger/period.rbs +7 -0
  43. data/stdlib/logger/severity.rbs +8 -0
  44. data/stdlib/pty/pty.rbs +159 -0
  45. metadata +13 -3
  46. data/lib/rbs/test/test_helper.rb +0 -180
@@ -0,0 +1,7 @@
1
+ module Logger::Period
2
+ def self?.next_rotate_time: (Time now, String shift_age) -> untyped
3
+
4
+ def self?.previous_period_end: (Time now, String shift_age) -> untyped
5
+
6
+ SiD: Integer
7
+ end
@@ -0,0 +1,8 @@
1
+ module Logger::Severity
2
+ DEBUG: 0
3
+ INFO: 1
4
+ WARN: 2
5
+ ERROR: 3
6
+ FATAL: 4
7
+ UNKNOWN: 5
8
+ end
@@ -0,0 +1,159 @@
1
+ # Creates and manages pseudo terminals (PTYs). See also
2
+ # http://en.wikipedia.org/wiki/Pseudo_terminal
3
+ #
4
+ # PTY allows you to allocate new terminals using ::open or ::spawn a new
5
+ # terminal with a specific command.
6
+ #
7
+ # ## Example
8
+ #
9
+ # In this example we will change the buffering type in the `factor` command,
10
+ # assuming that factor uses stdio for stdout buffering.
11
+ #
12
+ # If IO.pipe is used instead of PTY.open, this code deadlocks because factor's
13
+ # stdout is fully buffered.
14
+ #
15
+ # # start by requiring the standard library PTY
16
+ # require 'pty'
17
+ #
18
+ # master, slave = PTY.open
19
+ # read, write = IO.pipe
20
+ # pid = spawn("factor", :in=>read, :out=>slave)
21
+ # read.close # we dont need the read
22
+ # slave.close # or the slave
23
+ #
24
+ # # pipe "42" to the factor command
25
+ # write.puts "42"
26
+ # # output the response from factor
27
+ # p master.gets #=> "42: 2 3 7\n"
28
+ #
29
+ # # pipe "144" to factor and print out the response
30
+ # write.puts "144"
31
+ # p master.gets #=> "144: 2 2 2 2 3 3\n"
32
+ # write.close # close the pipe
33
+ #
34
+ # # The result of read operation when pty slave is closed is platform
35
+ # # dependent.
36
+ # ret = begin
37
+ # master.gets # FreeBSD returns nil.
38
+ # rescue Errno::EIO # GNU/Linux raises EIO.
39
+ # nil
40
+ # end
41
+ # p ret #=> nil
42
+ #
43
+ # ## License
44
+ #
45
+ # C) Copyright 1998 by Akinori Ito.
46
+ #
47
+ # This software may be redistributed freely for this purpose, in full
48
+ # or in part, provided that this entire copyright notice is included
49
+ # on any copies of this software and applications and derivations thereof.
50
+ #
51
+ # This software is provided on an "as is" basis, without warranty of any
52
+ # kind, either expressed or implied, as to any matter including, but not
53
+ # limited to warranty of fitness of purpose, or merchantability, or
54
+ # results obtained from use of this software.
55
+ #
56
+ module PTY
57
+ # Checks the status of the child process specified by `pid`. Returns `nil` if
58
+ # the process is still alive.
59
+ #
60
+ # If the process is not alive, and `raise` was true, a PTY::ChildExited
61
+ # exception will be raised. Otherwise it will return a Process::Status instance.
62
+ #
63
+ # `pid`
64
+ # : The process id of the process to check
65
+ # `raise`
66
+ # : If `true` and the process identified by `pid` is no longer alive a
67
+ # PTY::ChildExited is raised.
68
+ def self.check: (Integer pid) -> (Process::Status | nil)
69
+ | (Integer pid, FalseClass raise) -> (Process::Status | nil)
70
+ | (Integer pid, TrueClass raise) -> nil
71
+
72
+ # Spawns the specified command on a newly allocated pty. You can also use the
73
+ # alias ::getpty.
74
+ #
75
+ # The command's controlling tty is set to the slave device of the pty and its
76
+ # standard input/output/error is redirected to the slave device.
77
+ #
78
+ # `command` and `command_line` are the full commands to run, given a String. Any
79
+ # additional `arguments` will be passed to the command.
80
+ #
81
+ # ### Return values
82
+ #
83
+ # In the non-block form this returns an array of size three, `[r, w, pid]`.
84
+ #
85
+ # In the block form these same values will be yielded to the block:
86
+ #
87
+ # `r`
88
+ # : A readable IO that contains the command's standard output and standard
89
+ # error
90
+ # `w`
91
+ # : A writable IO that is the command's standard input
92
+ # `pid`
93
+ # : The process identifier for the command.
94
+ def self.getpty: (*String command) -> [ IO, IO, Integer ]
95
+ | (*String command) { ([ IO ,IO , Integer ]) -> untyped } -> untyped
96
+
97
+ # Allocates a pty (pseudo-terminal).
98
+ #
99
+ # In the block form, yields two arguments `master_io, slave_file` and the value
100
+ # of the block is returned from `open`.
101
+ #
102
+ # The IO and File are both closed after the block completes if they haven't been
103
+ # already closed.
104
+ #
105
+ # PTY.open {|master, slave|
106
+ # p master #=> #<IO:masterpty:/dev/pts/1>
107
+ # p slave #=> #<File:/dev/pts/1>
108
+ # p slave.path #=> "/dev/pts/1"
109
+ # }
110
+ #
111
+ # In the non-block form, returns a two element array, `[master_io, slave_file]`.
112
+ #
113
+ # master, slave = PTY.open
114
+ # # do something with master for IO, or the slave file
115
+ #
116
+ # The arguments in both forms are:
117
+ #
118
+ # `master_io`
119
+ # : the master of the pty, as an IO.
120
+ # `slave_file`
121
+ # : the slave of the pty, as a File. The path to the terminal device is
122
+ # available via `slave_file.path`
123
+ #
124
+ #
125
+ # IO#raw! is usable to disable newline conversions:
126
+ #
127
+ # require 'io/console'
128
+ # PTY.open {|m, s|
129
+ # s.raw!
130
+ # ...
131
+ # }
132
+ def self.open: () -> [ IO, File ]
133
+ | () { ([ IO , File ]) -> untyped } -> untyped
134
+
135
+ # Spawns the specified command on a newly allocated pty. You can also use the
136
+ # alias ::getpty.
137
+ #
138
+ # The command's controlling tty is set to the slave device of the pty and its
139
+ # standard input/output/error is redirected to the slave device.
140
+ #
141
+ # `command` and `command_line` are the full commands to run, given a String. Any
142
+ # additional `arguments` will be passed to the command.
143
+ #
144
+ # ### Return values
145
+ #
146
+ # In the non-block form this returns an array of size three, `[r, w, pid]`.
147
+ #
148
+ # In the block form these same values will be yielded to the block:
149
+ #
150
+ # `r`
151
+ # : A readable IO that contains the command's standard output and standard
152
+ # error
153
+ # `w`
154
+ # : A writable IO that is the command's standard input
155
+ # `pid`
156
+ # : The process identifier for the command.
157
+ def self.spawn: (*String command) -> [ IO, IO, Integer ]
158
+ | (*String command) {([ IO , IO , Integer ]) -> untyped } -> untyped
159
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-03 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -41,6 +41,7 @@ files:
41
41
  - docs/stdlib.md
42
42
  - docs/syntax.md
43
43
  - exe/rbs
44
+ - goodcheck.yml
44
45
  - lib/rbs.rb
45
46
  - lib/rbs/ast/annotation.rb
46
47
  - lib/rbs/ast/comment.rb
@@ -57,6 +58,7 @@ files:
57
58
  - lib/rbs/environment_loader.rb
58
59
  - lib/rbs/environment_walker.rb
59
60
  - lib/rbs/errors.rb
61
+ - lib/rbs/factory.rb
60
62
  - lib/rbs/location.rb
61
63
  - lib/rbs/method_type.rb
62
64
  - lib/rbs/namespace.rb
@@ -69,9 +71,11 @@ files:
69
71
  - lib/rbs/test.rb
70
72
  - lib/rbs/test/errors.rb
71
73
  - lib/rbs/test/hook.rb
74
+ - lib/rbs/test/observer.rb
72
75
  - lib/rbs/test/setup.rb
76
+ - lib/rbs/test/setup_helper.rb
73
77
  - lib/rbs/test/spy.rb
74
- - lib/rbs/test/test_helper.rb
78
+ - lib/rbs/test/tester.rb
75
79
  - lib/rbs/test/type_check.rb
76
80
  - lib/rbs/type_name.rb
77
81
  - lib/rbs/type_name_resolver.rb
@@ -157,10 +161,16 @@ files:
157
161
  - stdlib/find/find.rbs
158
162
  - stdlib/ipaddr/ipaddr.rbs
159
163
  - stdlib/json/json.rbs
164
+ - stdlib/logger/formatter.rbs
165
+ - stdlib/logger/log_device.rbs
166
+ - stdlib/logger/logger.rbs
167
+ - stdlib/logger/period.rbs
168
+ - stdlib/logger/severity.rbs
160
169
  - stdlib/mutex_m/mutex_m.rbs
161
170
  - stdlib/pathname/pathname.rbs
162
171
  - stdlib/prime/integer-extension.rbs
163
172
  - stdlib/prime/prime.rbs
173
+ - stdlib/pty/pty.rbs
164
174
  - stdlib/securerandom/securerandom.rbs
165
175
  - stdlib/set/set.rbs
166
176
  - stdlib/tmpdir/tmpdir.rbs
@@ -1,180 +0,0 @@
1
- module RBS
2
- module Test
3
- module TypeAssertions
4
- module ClassMethods
5
- attr_reader :target
6
-
7
- def library(*libs)
8
- @libs = libs
9
- @env = nil
10
- @target = nil
11
- end
12
-
13
- def env
14
- @env ||= begin
15
- loader = RBS::EnvironmentLoader.new
16
- (@libs || []).each do |lib|
17
- loader.add library: lib
18
- end
19
-
20
- RBS::Environment.from_loader(loader).resolve_type_names
21
- end
22
- end
23
-
24
- def builder
25
- @builder ||= DefinitionBuilder.new(env: env)
26
- end
27
-
28
- def testing(type_or_string)
29
- type = case type_or_string
30
- when String
31
- RBS::Parser.parse_type(type_or_string, variables: [])
32
- else
33
- type_or_string
34
- end
35
-
36
- definition = case type
37
- when Types::ClassInstance
38
- builder.build_instance(type.name)
39
- when Types::ClassSingleton
40
- builder.build_singleton(type.name)
41
- else
42
- raise "Test target should be class instance or class singleton: #{type}"
43
- end
44
-
45
- @target = [type, definition]
46
- end
47
- end
48
-
49
- def self.included(base)
50
- base.extend ClassMethods
51
- end
52
-
53
- def env
54
- self.class.env
55
- end
56
-
57
- def builder
58
- self.class.builder
59
- end
60
-
61
- def targets
62
- @targets ||= []
63
- end
64
-
65
- def target
66
- targets.last || self.class.target
67
- end
68
-
69
- def testing(type_or_string)
70
- type = case type_or_string
71
- when String
72
- RBS::Parser.parse_type(type_or_string, variables: [])
73
- else
74
- type_or_string
75
- end
76
-
77
- definition = case type
78
- when Types::ClassInstance
79
- builder.build_instance(type.name)
80
- when Types::ClassSingleton
81
- builder.build_singleton(type.name)
82
- else
83
- raise "Test target should be class instance or class singleton: #{type}"
84
- end
85
-
86
- targets.push [type, definition]
87
-
88
- if block_given?
89
- begin
90
- yield
91
- ensure
92
- targets.pop
93
- end
94
- else
95
- [type, definition]
96
- end
97
- end
98
-
99
- ruby2_keywords def assert_send_type(method_type, receiver, method, *args, &block)
100
- trace = []
101
- spy = Spy.wrap(receiver, method)
102
- spy.callback = -> (result) { trace << result }
103
-
104
- exception = nil
105
-
106
- begin
107
- spy.wrapped_object.__send__(method, *args, &block)
108
- rescue => exn
109
- exception = exn
110
- end
111
-
112
- mt = case method_type
113
- when String
114
- RBS::Parser.parse_method_type(method_type, variables: [])
115
- when RBS::MethodType
116
- method_type
117
- end
118
-
119
- typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
120
- errors = typecheck.method_call(method, mt, trace.last, errors: [])
121
-
122
- assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.last.inspect}"
123
-
124
- type, definition = target
125
- method_types = case
126
- when definition.instance_type?
127
- subst = Substitution.build(definition.type_params, type.args)
128
- definition.methods[method].method_types.map do |method_type|
129
- method_type.sub(subst)
130
- end
131
- when definition.class_type?
132
- definition.methods[method].method_types
133
- end
134
-
135
- all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
136
- assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"
137
-
138
- if exception
139
- raise exception
140
- end
141
- end
142
-
143
- ruby2_keywords def refute_send_type(method_type, receiver, method, *args, &block)
144
- trace = []
145
- spy = Spy.wrap(receiver, method)
146
- spy.callback = -> (result) { trace << result }
147
-
148
- exception = nil
149
- begin
150
- spy.wrapped_object.__send__(method, *args, &block)
151
- rescue Exception => exn
152
- exception = exn
153
- end
154
-
155
- mt = case method_type
156
- when String
157
- RBS::Parser.parse_method_type(method_type, variables: [])
158
- when RBS::MethodType
159
- method_type
160
- end
161
-
162
- mt = mt.update(block: if mt.block
163
- MethodType::Block.new(
164
- type: mt.block.type.with_return_type(Types::Bases::Any.new(location: nil)),
165
- required: mt.block.required
166
- )
167
- end,
168
- type: mt.type.with_return_type(Types::Bases::Any.new(location: nil)))
169
-
170
- typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
171
- errors = typecheck.method_call(method, mt, trace.last, errors: [])
172
-
173
- assert_operator exception, :is_a?, ::Exception
174
- assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
175
-
176
- exception
177
- end
178
- end
179
- end
180
- end