This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
54 lines (44 loc) · 1.36 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'tmpdir'
require 'fileutils'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
task :default => :greatest
desc "Run C tests"
task :greatest do
Dir.mktmpdir do |d|
test_suite_path = File.join(d, "test_suite.c")
mk_test_suite_file(test_suite_path)
args = "-pedantic -Wall -Wextra -Werror -std=c99 -Isupport/c/test -Isupport/c/src -I#{d}"
srcs = "support/c/src/cauterize.c support/c/test/test.c"
bin = File.join(d, "test.bin")
sh "gcc #{args} #{srcs} -o #{bin}"
sh bin
end
end
desc "Run C# tests"
task :nunit do
cd "support/cs" do
FileUtils.mkdir_p "lib"
sh "dmcs -target:library -out:lib/Cauterize.dll src/*.cs"
references = "-r:lib/nunit.framework.dll -r:lib/Moq.dll -r:lib/Cauterize.dll"
sh "dmcs -target:library #{references} -out:lib/Cauterize.Test.dll test/*.cs"
sh "#{nunit} lib/*.dll"
end
end
def nunit
"nunit-console4"
end
# Support Methods
SUITE_ENTRY_TEMPLATE = " RUN_TEST(%s);"
def mk_test_suite_file(path)
test_files = Dir["support/c/test/*.c"]
suite_text = test_files.map do |test_file|
File.read(test_file).lines.map do |l|
m = l.match(/^TEST (?<sym>[^\(]+)\(\)/)
m ? m[:sym] : nil
end.compact
end.flatten.map {|t| SUITE_ENTRY_TEMPLATE % t}.join("\n") + "\n"
File.open(path, "wb") {|fh| fh.write(suite_text)}
end