Add an argument parser

This commit is contained in:
2022-06-05 23:43:45 +02:00
parent 5490f6ce1c
commit aa6b2504bd
2 changed files with 172 additions and 17 deletions

View File

@ -4,8 +4,12 @@ require 'open3'
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
BINARY = 'build/bin/elna'
TESTS = FileList['tests/*.elna']
.map { |test| (Pathname.new('build') + test).sub_ext('').to_path }
TESTS = FileList['tests/*.elna'].flat_map do |test|
build = Pathname.new 'build'
asm_test = build + 'asm' + Pathname.new(test).basename('')
[build + test, asm_test].map { |path| path.sub_ext('').to_path }
end
SOURCES = FileList['source/**/*.d']
directory 'build'
@ -13,22 +17,24 @@ directory 'build'
CLEAN.include 'build'
CLEAN.include '.dub'
rule(/build\/tests\/.+/ => ->(file) { test_for_out(file) }) do |t|
rule(/build\/tests\/[^\/\.]+$/ => ->(file) { test_for_out(file) }) do |t|
sh 'gcc', '-o', t.name, "#{t.name}.o"
end
rule(/build\/asm\/[^\/\.]+$/ => ->(file) { test_for_object(file) }) do |t|
Pathname.new(t.name).dirname.mkpath
Open3.pipeline [BINARY, t.source], ['gcc', '-x', 'assembler', '-o', t.name, '-']
end
rule(/build\/tests\/.+\.o$/ => ->(file) { test_for_object(file) }) do |t|
Pathname.new(t.name).dirname.mkpath
sh BINARY, t.source
sh 'gcc', '-o', t.name, "#{t.name}.o"
# Open3.pipeline [BINARY, t.source], ['gcc', '-x', 'assembler', '-o', t.name, '-']
end
file BINARY => SOURCES do |t|
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc-12')
end
file 'build/tests/sample' => BINARY do |t|
sh t.source
sh 'gcc', '-o', t.name, 'build/tests/sample.o'
end
task default: BINARY
desc 'Run all tests and check the results'
@ -38,7 +44,7 @@ task test: BINARY do
expected = Pathname
.new(test)
.sub_ext('.txt')
.sub(/^build\/tests\//, 'tests/expectations/')
.sub(/^build\/[[:alpha:]]+\//, 'tests/expectations/')
.read
.to_i
@ -48,10 +54,6 @@ task test: BINARY do
fail "#{test}: Expected #{expected}, got #{actual}" unless expected == actual
end
# system './build/tests/sample'
# actual = $?.exitstatus
# fail "./build/tests/sample: Expected 3, got #{actual}" unless 3 == actual
end
desc 'Run unittest blocks'
@ -59,11 +61,18 @@ task unittest: SOURCES do |t|
sh('dub', 'test', '--compiler=gdc-12')
end
def test_for_out(out_file)
def test_for_object(out_file)
test_source = Pathname
.new(out_file)
.sub_ext('.elna')
.sub(/^build\//, '')
.sub(/^build\/[[:alpha:]]+\//, 'tests/')
.to_path
[test_source, BINARY]
end
def test_for_out(out_file)
Pathname
.new(out_file)
.sub_ext('.o')
.to_path
end