Initial commit
This commit is contained in:
69
Rakefile
Normal file
69
Rakefile
Normal file
@ -0,0 +1,69 @@
|
||||
require 'pathname'
|
||||
require 'rake/clean'
|
||||
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 }
|
||||
SOURCES = FileList['source/**/*.d']
|
||||
|
||||
directory 'build'
|
||||
|
||||
CLEAN.include 'build'
|
||||
CLEAN.include '.dub'
|
||||
|
||||
rule(/build\/tests\/.+/ => ->(file) { test_for_out(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'
|
||||
task test: TESTS
|
||||
task test: BINARY do
|
||||
TESTS.each do |test|
|
||||
expected = Pathname
|
||||
.new(test)
|
||||
.sub_ext('.txt')
|
||||
.sub(/^build\/tests\//, 'tests/expectations/')
|
||||
.read
|
||||
.to_i
|
||||
|
||||
puts "Running #{test}"
|
||||
system test
|
||||
actual = $?.exitstatus
|
||||
|
||||
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'
|
||||
task unittest: SOURCES do |t|
|
||||
sh('dub', 'test', '--compiler=gdc-12')
|
||||
end
|
||||
|
||||
def test_for_out(out_file)
|
||||
test_source = Pathname
|
||||
.new(out_file)
|
||||
.sub_ext('.elna')
|
||||
.sub(/^build\//, '')
|
||||
.to_path
|
||||
[test_source, BINARY]
|
||||
end
|
Reference in New Issue
Block a user