Rdb: Ruby-Nachbau der MWC /rdb-Werkzeuge

This commit is contained in:
wkh
2026-10-11 20:33:17 +02:00
commit a9990169e9
308 changed files with 16738 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
# frozen_string_literal: true
require 'minitest/autorun'
require 'open3'
require 'tmpdir'
require 'fileutils'
ROOT = File.expand_path('..', __dir__)
BIN = File.join(ROOT, 'bin')
DEMO = File.join(ROOT, 'demo')
# Each test runs in a scratch copy of demo/, so commands that change files
# (append, delete, replace ...) never touch the originals.
class RdbCase < Minitest::Test
def setup
@dir = Dir.mktmpdir('rdb-test')
FileUtils.cp_r(Dir[File.join(DEMO, '*')], @dir)
end
def teardown
FileUtils.remove_entry(@dir)
end
# Run a command through its symlink; returns [stdout, stderr, status].
def run3(cmd, *args, stdin: '', env: {})
Open3.capture3({ 'PATH' => "#{BIN}:#{ENV['PATH']}" }.merge(env), File.join(BIN, cmd), *args,
stdin_data: stdin, chdir: @dir)
end
def rdb(cmd, *args, stdin: nil, file: nil)
stdin = File.read(File.join(@dir, file)) if file
out, err, st = run3(cmd, *args, stdin: stdin.to_s)
assert st.success?, "#{cmd} #{args.join(' ')} failed: #{err}"
out
end
# Output as rows of cells, without the head and dash lines.
def data(out)
out.lines.drop(2).map { |l| l.chomp.split("\t", -1) }
end
def read(name)
File.read(File.join(@dir, name))
end
def write(name, text)
File.write(File.join(@dir, name), text)
end
end