forked from canton7/Stylet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
164 lines (124 loc) · 4.91 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
CONFIG = ENV['CONFIG'] || 'Debug'
COVERAGE_DIR = 'Coverage'
COVERAGE_FILE = File.join(COVERAGE_DIR, 'coverage.xml')
GITLINK_REMOTE = 'https://github.com/canton7/stylet'
NUSPEC = 'NuGet/Stylet.nuspec'
ASSEMBLY_INFO = 'Stylet/Properties/AssemblyInfo.cs'
CSPROJ = 'Stylet/Stylet.csproj'
MSBUILD = %q{C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe}
directory COVERAGE_DIR
desc "Build the project for release"
task :build do
sh MSBUILD, CSPROJ, "/t:Clean;Rebuild", "/p:Configuration=Release", "/verbosity:normal"
end
task :test_environment => [:build] do
NUNIT_TOOLS = 'packages/NUnit.Runners.*/tools'
NUNIT_CONSOLE = Dir[File.join(NUNIT_TOOLS, 'nunit-console.exe')].first
NUNIT_EXE = Dir[File.join(NUNIT_TOOLS, 'nunit.exe')].first
OPENCOVER_CONSOLE = Dir['packages/OpenCover.*/tools/OpenCover.Console.exe'].first
REPORT_GENERATOR = Dir['packages/ReportGenerator.*/tools/ReportGenerator.exe'].first
UNIT_TESTS_DLL = "StyletUnitTests/bin/#{CONFIG}/StyletUnitTests.dll"
INTEGRATION_TESTS_EXE = "StyletIntegrationTests/bin/#{CONFIG}/StyletIntegrationTests.exe"
raise "NUnit.Runners not found. Restore NuGet packages" unless NUNIT_CONSOLE && NUNIT_EXE
raise "OpenCover not found. Restore NuGet packages" unless OPENCOVER_CONSOLE
raise "ReportGenerator not found. Restore NuGet packages" unless REPORT_GENERATOR
end
task :nunit_test_runner => [:test_environment] do
sh NUNIT_CONSOLE, UNIT_TESTS_DLL
end
desc "Run unit tests using the current CONFIG (or Debug)"
task :test => [:nunit_test_runner] do |t|
rm 'TestResult.xml', :force => true
end
desc "Launch the NUnit gui pointing at the correct DLL for CONFIG (or Debug)"
task :nunit => [:test_environment] do |t|
sh NUNIT_EXE, UNIT_TESTS_DLL
end
namespace :cover do
desc "Generate unit test code coverage reports for CONFIG (or Debug)"
task :unit => [:test_environment, COVERAGE_DIR] do |t|
coverage(instrument(:nunit, UNIT_TESTS_DLL))
end
desc "Create integration test code coverage reports for CONFIG (or Debug)"
task :integration => [:test_environment, COVERAGE_DIR] do |t|
coverage(instrument(:exe, INTEGRATION_TESTS_EXE))
end
desc "Create test code coverage for everything for CONFIG (or Debug)"
task :all => [:test_environment, COVERAGE_DIR] do |t|
coverage([instrument(:nunit, UNIT_TESTS_DLL), instrument(:exe, INTEGRATION_TESTS_EXE)])
end
end
def instrument(runner, target)
case runner
when :nunit
opttarget = NUNIT_CONSOLE
opttargetargs = target
when :exe
opttarget = target
opttargetargs = ''
else
raise "Unknown runner #{runner}"
end
coverage_file = File.join(COVERAGE_DIR, File.basename(target).ext('xml'))
sh OPENCOVER_CONSOLE, %Q{-register:user -target:"#{opttarget}" -filter:"+[Stylet]* -[Stylet]XamlGeneratedNamespace.*" -targetargs:"#{opttargetargs} /noshadow" -output:"#{coverage_file}"}
rm('TestResult.xml', :force => true) if runner == :nunit
coverage_file
end
def coverage(coverage_files)
coverage_files = [*coverage_files]
sh REPORT_GENERATOR, %Q{-reports:"#{coverage_files.join(';')}" "-targetdir:#{COVERAGE_DIR}"}
end
desc "Create NuGet package"
task :package do
local_hash = `git rev-parse HEAD`.chomp
sh "NuGet/GitLink.exe . -s #{local_hash} -u #{GITLINK_REMOTE} -f Stylet.sln -ignore StyletUnitTests,StyletIntegrationTests"
Dir.chdir(File.dirname(NUSPEC)) do
sh "nuget.exe pack #{File.basename(NUSPEC)}"
end
end
desc "Bump version number"
task :version, [:version] do |t, args|
parts = args[:version].split('.')
parts << '0' if parts.length == 3
version = parts.join('.')
content = IO.read(ASSEMBLY_INFO)
content[/^\[assembly: AssemblyVersion\(\"(.+?)\"\)\]/, 1] = version
content[/^\[assembly: AssemblyFileVersion\(\"(.+?)\"\)\]/, 1] = version
File.open(ASSEMBLY_INFO, 'w'){ |f| f.write(content) }
content = IO.read(NUSPEC)
content[/<version>(.+?)<\/version>/, 1] = args[:version]
File.open(NUSPEC, 'w'){ |f| f.write(content) }
end
desc "Extract StyletIoC as a standalone file"
task :"extract-stylet-ioc" do
filenames = Dir['Stylet/StyletIoC/**/*.cs']
usings = Set.new
files = []
filenames.each do |file|
contents = File.read(file)
file_usings = contents.scan(/using .*?;$/)
usings.merge(file_usings)
matches = contents.match(/namespace (.+?)\n{\n(.+)}.*/m)
namespace, file_contents = matches.captures
files << {
:from => file,
:contents => file_contents,
:namespace => namespace
}
# merged_contents << " // Originally from #{file}\n\n" << file_contents << "\n"
end
File.open('StyletIoC.cs', 'w') do |outf|
outf.write(usings.to_a.join("\n"))
outf.puts
files.group_by{ |x| x[:namespace ] }.each do |namespace, ns_files|
outf.puts("\nnamespace #{namespace}")
outf.puts("{")
ns_files.each do |file|
outf.puts("\n // Originally from #{file[:from]}\n\n")
outf.puts(file[:contents])
end
outf.puts("}\n")
end
end
# puts merged_contents
end