2021-12-18 00:17:33 -05:00
|
|
|
# Ruby Hacking Guide
|
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
This document gives some helpful instructions which should make your
|
|
|
|
experience as a Ruby core developer easier.
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2021-12-18 02:39:57 -05:00
|
|
|
## Setup
|
|
|
|
|
|
|
|
### Make
|
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
It's common to want to compile things as quickly as possible. Ensuring
|
|
|
|
`make` has the right `--jobs` flag will ensure all processors are
|
|
|
|
utilized when building software projects To do this effectively, you
|
|
|
|
can set `MAKEFLAGS` in your shell configuration/profile:
|
2021-12-18 02:39:57 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
# On macOS with Fish shell:
|
|
|
|
export MAKEFLAGS="--jobs "(sysctl -n hw.ncpu)
|
2021-12-18 02:39:57 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
# On macOS with Bash/ZSH shell:
|
|
|
|
export MAKEFLAGS="--jobs $(sysctl -n hw.ncpu)"
|
2021-12-18 02:39:57 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
# On Linux with Fish shell:
|
|
|
|
export MAKEFLAGS="--jobs "(nproc)
|
2021-12-18 02:39:57 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
# On Linux with Bash/ZSH shell:
|
|
|
|
export MAKEFLAGS="--jobs $(nproc)"
|
|
|
|
```
|
2021-12-18 02:39:57 -05:00
|
|
|
|
2021-12-18 00:17:33 -05:00
|
|
|
## Configure Ruby
|
|
|
|
|
|
|
|
It's generally advisable to use a build directory.
|
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
./autogen.sh
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
../configure --prefix $HOME/.rubies/ruby-head
|
|
|
|
make install
|
|
|
|
```
|
2021-12-18 00:17:33 -05:00
|
|
|
|
|
|
|
### Without Documentation
|
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
If you are frequently building Ruby, this will reduce the time it
|
|
|
|
takes to `make install`.
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
../configure --disable-install-doc
|
|
|
|
```
|
2021-12-18 00:17:33 -05:00
|
|
|
|
|
|
|
## Running Ruby
|
|
|
|
|
|
|
|
### Run Local Test Script
|
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
You can create a file in the Ruby source root called `test.rb`. You
|
|
|
|
can build `miniruby` and execute this script:
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
make run
|
|
|
|
```
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
If you want more of the standard library, you can use `runruby`
|
|
|
|
instead of `run`.
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2022-01-08 22:39:26 -05:00
|
|
|
## Running Tests
|
|
|
|
|
|
|
|
You can run the following tests at once:
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
make check
|
|
|
|
```
|
|
|
|
|
2021-12-18 00:17:33 -05:00
|
|
|
### Run Bootstrap Tests
|
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
There are a set of tests in `bootstraptest/` which cover most basic
|
|
|
|
features of the core Ruby language.
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
make test
|
|
|
|
```
|
2021-12-18 00:17:33 -05:00
|
|
|
|
|
|
|
### Run Extensive Tests
|
|
|
|
|
2022-01-08 22:41:30 -05:00
|
|
|
There are extensive tests in `test/` which cover a wide range of
|
|
|
|
features of the Ruby core language.
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
make test-all
|
|
|
|
```
|
2021-12-18 00:17:33 -05:00
|
|
|
|
|
|
|
You can run specific tests by specifying their path:
|
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
|
|
|
make test-all TESTS=../test/fiber/test_io.rb
|
|
|
|
```
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2022-01-10 11:39:36 -05:00
|
|
|
### Run Ruby Spec Suite Tests
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2022-01-10 11:39:36 -05:00
|
|
|
The [Ruby Spec Suite](https://github.com/ruby/spec/) is a test suite
|
|
|
|
that aims to provide an executable description for the behavior of the
|
|
|
|
language.
|
2021-12-18 00:17:33 -05:00
|
|
|
|
2021-12-18 03:42:17 -05:00
|
|
|
``` shell
|
2022-01-08 22:34:11 -05:00
|
|
|
make test-spec
|
2021-12-18 03:42:17 -05:00
|
|
|
```
|