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

Add a generator of stdlib test #79

Merged
merged 1 commit into from
Nov 13, 2019
Merged
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
26 changes: 26 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,30 @@ task :test => :parser
task :stdlib_test => :parser
task :build => :parser

namespace :generate do
task :stdlib_test, [:class] do |_task, args|
klass = args.fetch(:class) do
raise "Class name is necessary. e.g. rake 'generate:stdlib_test[String]'"
end

path = Pathname("test/stdlib/#{klass}_test.rb")
raise "#{path} already exists!" if path.exist?

path.write <<~RUBY
class #{klass}Test < StdlibTest
target #{klass}
using hook.refinement

# def test_method_name
# # Call the method
# method_name(arg)
# method_name(arg, arg2)
# end
end
RUBY

puts "Created: #{path}"
end
end

CLEAN.include("lib/ruby/signature/parser.rb")
11 changes: 9 additions & 2 deletions doc/stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ We support writing tests for stdlib signatures.

### Writing tests

Put the test scripts in `test/stdlib` directory with `[class_name]_test.rb`, like `String_test.rb` and `File_test.rb`.
First, execute `generate:stdlib_test` rake task with a class name that you want to test.

```bash
$ bundle exec rake 'generate:stdlib_test[String]'
Created: test/stdlib/String_test.rb
```

It generates `test/stdlib/[class_name]_test.rb`.
The test scripts would look like the following:

```rb
Expand All @@ -39,7 +46,7 @@ You need two method calls, `target` and `using`.
`using hook.refinement` installs a special instrumentation for stdlib, based on refinements.
And you write the sample programs which calls all of the patterns of overloads.

Note that the instrumentation is based on refinmenets and you need to write all method calls in the unit class definitions.
Note that the instrumentation is based on refinements and you need to write all method calls in the unit class definitions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

If the execution of the program escape from the class definition, the instrumentation is disabled and no check will be done.

### Running tests
Expand Down