Running Tests

Running tests

There are a bunch of ways to verify your changes to Ruby after you’ve build the binary. Which one you’ll use will depend on where you’re working in the codebase, and how quickly you need feedback.

From fastest (least coverage) to slowest (most coverage), these are:

Running specific tests

You can run selected test files using make directly. It will run the tests in the order you specify

make path/to/test/file.rb path/to/another/test.rb


You can configure what make runs by setting some environment variables. When you run the tests make builds a command to run that consists broadly of three parts: A ruby interpreter, a wrapper script to run ruby with a set configuration, and a test runner that calls the ruby wrapper script to run tests with the specified ruby configuration. Each level can be modified:

I have no idea where to find a comprehensive list of what options can be used, I suspect that I’ll be discovering new things forever. But here is a useful command pulled from my shell history:

make test-all TESTOPTS="-v --seed=7791" RUNRUBYOPT="--debugger=lldb"

This says: run all the tests in single threaded mode (-v), in a specific order (--seed) and using the lldb debugger, so I can step through a crash.

Excluded tests

Ruby excludes some tests from all runs, whether locally or on Github Actions CI. You can see this whenever you run the tests and it shows the following run command

❯ make test-all
Run options:
  "--ruby=./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems"

The last part --name=!/memory_leak/ is the interesting part - Ruby doesn’t run any test containing memory_leak in it’s name by default! If you’re actually trying to run (or write) the memory leak tests you can clear the excludes list using TEST_EXCLUDES

make test/ruby/test_class.rb TEST_EXCLUDES=""

You can also Run tests using the debugger [debugging]