Version 0.3.0: testall.cmds mit einem Beispiel pro Befehl

This commit is contained in:
wkh
2026-10-11 21:45:23 +02:00
parent 8f6dc852ff
commit 32c1f2be28
9 changed files with 1277 additions and 76 deletions
+3 -1
View File
@@ -165,10 +165,12 @@ Rdb.register('enter', 'Add rows to a table or list file without an editor', 'ent
end
end
require 'digest'
# ---- locks -------------------------------------------------------------------
def lock_file(name)
File.join(Dir.tmpdir, "L#{File.basename(name)}")
File.join(Dir.tmpdir, "L#{File.basename(name)}.#{Digest::MD5.hexdigest(File.expand_path(name))[0, 8]}")
end
Rdb.register('lock', 'Lock a record or field of a file', 'lock filename processid from to indexfrom indexto') do |args|
+1 -1
View File
@@ -365,7 +365,7 @@ Rdb.register('sale', 'Enter sale order, and item, update customer', 'sale') do |
next if items.empty?
tax = gross * 0.05
order = [n.to_s, cust, Date.today.strftime('%y%m%d'), '0', format('%.2f', gross), format('%.2f', tax), format('%.2f', gross + tax)]
order = [n.to_s, cust, next_date, '0', format('%.2f', gross), format('%.2f', tax), format('%.2f', gross + tax)]
puts Rdb::Table.new(%w[Number Cust Date Shipped Gross Tax Total], [order]).to_s
if ask('Is this correct? (y, n) ').downcase.start_with?('y')
File.write('salesorder', Rdb::Table.open('salesorder').tap { |t| t.rows << order }.to_s)
+17 -5
View File
@@ -227,12 +227,24 @@ end
Rdb.register('testall', 'Test all /rdb programs in directory $RDB/demo', 'testall [ > testall.new ]') do |_args|
ENV['PATH'] = "#{File.join(Rdb::ROOT, 'bin')}:#{ENV['PATH']}"
demo = File.join(ENV['RDB'] || Rdb::ROOT, 'demo')
Dir.chdir(demo)
script = File.join(demo, 'testall.cmds')
File.exist?(script) or die "#{script}: missing"
File.readlines(script, chomp: true).reject { |l| l.strip.empty? || l.start_with?('#') }.each do |cmd|
puts "$ #{cmd}"
$stdout.flush
puts `#{cmd} 2>&1`
# Run in a scratch copy: some commands (append, delete, close ...) change files.
Dir.mktmpdir('rdb-testall') do |dir|
FileUtils.cp_r(Dir[File.join(demo, '*')], dir)
Dir.chdir(dir)
File.readlines(script, chomp: true).each do |cmd|
next if cmd.strip.empty?
if cmd.start_with?('##') # '##' lines are shown, a single '#' is a silent comment
puts cmd
next
end
next if cmd.start_with?('#')
puts "$ #{cmd}"
$stdout.flush
puts Open3.capture2e('sh', '-c', cmd, stdin_data: '').first
end
end
end
+1 -1
View File
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Rdb
VERSION = '0.2.0'
VERSION = '0.3.0'
end