Files
rdb/test/test_helper.rb
T
wkh c2ea36c6d6 Schneller Start ohne RubyGems, Rational statt BigDecimal, Helfer in Rdb::Helpers
bin/rdb läuft mit --disable-gems (ca. 85 statt 170 ms je Befehl), dafür
rechnen Summen und /act mit Rational. Hilfsfunktionen und Konstanten liegen
nicht mehr auf Object, Kopf-/Strichzeile und awk-Aufruf an einer Stelle.
Tests laufen parallel: 21 statt 70 Sekunden.
2026-10-30 10:01:36 +01:00

54 lines
1.4 KiB
Ruby

# 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
# Tests spawn their own processes in their own directory, so they can run
# side by side (N=1 in MT_CPU runs them one at a time).
parallelize_me!
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