# Final report

I developed [Yamatanooroti](https://github.com/aycabta/yamatanooroti) to test rendering results of [Reline](https://github.com/ruby/reline) on real terminals.

Yamatanooroti provides `Yamatanooroti::TestCase`, an extension of test-unit gem, to run tests in any real terminal environment that might work in the current environment. Internally, it does the following:

- A user defines a test case with the form `class MyTest < Yamatanooroti::TestCase`
- When `Yamatanooroti::TestCase` detects that it has been inherited with `inherited`, each time a method is defined in `MyTest`, it retrieves the method in `method_added`, saves it, and removes it with `remove_method`. The reason for removing it is to prevent the test from running directly in this class
- Automatically define a class for each real terminal test environment. If there is more than one, all of them will automatically define a class
    - If vterm gem is installed, define `MyTest::TestVTerm` and redefine the `UnboundMethod` object of the removed method from `MyTest` with `define_method` to this class
    - On Windows, define `MyTest::WindowsTest` and port the method in the same way

Then the test is executed by executing the specified command, and further input keys to the executed process, and confirm the rendering result by assertion.

## vterm gem

The vterm gem is a Ruby binding of libvterm implemented as one of the real terminal environments used by Yamatanooroti. Most terminal software on Unix-like OSes use rendering libraries to process control codes and escape sequences, and the libvterm is one of the particularly oldest terminal libraries. Yamatanooroti automatically runs real terminal tests using vterm gem if vterm gem installed environment.

## Windows

Use the Console API and others of the Win32 API to launch a new command prompt during the test, retrieve the rendering results executed there and run real terminal tests.

It uses "W" suffix APIs that support full-width characters, to take care that full-width characters are used in input and output.

Currently, it isn't possible to launch a command prompt without displaying a window, so the command prompt will be displayed during the test run. I'm trying to find a way to make the window invisible since I can also input keys in the window manually.

The experiment using ConPTY introduced from Windows 10 was also done, but because ConPTY is just PTY and isn't related to the rendering, the experiment was stopped.

## vte3 gem

I tried to add the vte3 gem, which is the Ruby binding of libvte3, to the supported environment, but because [https://github.com/ruby-gnome/ruby-gnome/issues/1356](some features were not implemented) on [ruby-gnome](https://github.com/ruby-gnome/ruby-gnome), I couldn't use it to begin with.

## macOS

There have been many bug reports of Reline from Terminal.app and iTerm2, so we would like to put it in a supported environment, but we are not currently supporting it.

## Release

The aforementioned vterm gem and yamatanooroti gem have been released.

## After the project

I added a test using Yamatanooroti in the Reline repository and is running the test in the GitHub Actions CI. GitHub Actions doesn't provide a GUI, so I can't launch a command prompt window on Windows, and I'm using only vterm gem. In the future, on the Reline repository, I'll continue to automate testing on Windows and expand the content of testing.

And I'll be also proceeding with the verification of Terminal.app and iTerm2 on macOS and vte3 gem, to support them by Yamatanooroti.
