mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Setup code coverage to be runable on demand
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -29,7 +29,10 @@ msbuild.log
|
||||
msbuild.err
|
||||
msbuild.wrn
|
||||
|
||||
|
||||
# code coverage artifacts
|
||||
node_modules
|
||||
packages
|
||||
coverage.xml
|
||||
|
||||
# Cross building rootfs
|
||||
cross/rootfs/
|
||||
|
||||
55
test/CodeCoverage/ReplaceText.vbs
Normal file
55
test/CodeCoverage/ReplaceText.vbs
Normal file
@@ -0,0 +1,55 @@
|
||||
' ReplaceText.vbs
|
||||
' Copied from answer at http://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file
|
||||
|
||||
Option Explicit
|
||||
|
||||
Const ForAppending = 8
|
||||
Const TristateFalse = 0 ' the value for ASCII
|
||||
Const Overwrite = True
|
||||
|
||||
Const WindowsFolder = 0
|
||||
Const SystemFolder = 1
|
||||
Const TemporaryFolder = 2
|
||||
|
||||
Dim FileSystem
|
||||
Dim Filename, OldText, NewText
|
||||
Dim OriginalFile, TempFile, Line
|
||||
Dim TempFilename
|
||||
|
||||
If WScript.Arguments.Count = 3 Then
|
||||
Filename = WScript.Arguments.Item(0)
|
||||
OldText = WScript.Arguments.Item(1)
|
||||
NewText = WScript.Arguments.Item(2)
|
||||
Else
|
||||
Wscript.Echo "Usage: ReplaceText.vbs <Filename> <OldText> <NewText>"
|
||||
Wscript.Quit
|
||||
End If
|
||||
|
||||
Set FileSystem = CreateObject("Scripting.FileSystemObject")
|
||||
Dim tempFolder: tempFolder = FileSystem.GetSpecialFolder(TemporaryFolder)
|
||||
TempFilename = FileSystem.GetTempName
|
||||
|
||||
If FileSystem.FileExists(TempFilename) Then
|
||||
FileSystem.DeleteFile TempFilename
|
||||
End If
|
||||
|
||||
Set TempFile = FileSystem.CreateTextFile(TempFilename, Overwrite, TristateFalse)
|
||||
Set OriginalFile = FileSystem.OpenTextFile(Filename)
|
||||
|
||||
Do Until OriginalFile.AtEndOfStream
|
||||
Line = OriginalFile.ReadLine
|
||||
|
||||
If InStr(Line, OldText) > 0 Then
|
||||
Line = Replace(Line, OldText, NewText)
|
||||
End If
|
||||
|
||||
TempFile.WriteLine(Line)
|
||||
Loop
|
||||
|
||||
OriginalFile.Close
|
||||
TempFile.Close
|
||||
|
||||
FileSystem.DeleteFile Filename
|
||||
FileSystem.MoveFile TempFilename, Filename
|
||||
|
||||
Wscript.Quit
|
||||
11
test/CodeCoverage/codecoverage.bat
Normal file
11
test/CodeCoverage/codecoverage.bat
Normal file
@@ -0,0 +1,11 @@
|
||||
SET WORKINGDIR=%~dp0
|
||||
rmdir %WORKINGDIR%reports\ /S /Q
|
||||
del %WORKINGDIR%coverage.xml
|
||||
mkdir reports
|
||||
COPY /Y %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json.BAK
|
||||
cscript /nologo ReplaceText.vbs %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json portable full
|
||||
dotnet build %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json
|
||||
"%WORKINGDIR%packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\project.json" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\bin\Debug\netcoreapp1.0
|
||||
"%WORKINGDIR%packages\ReportGenerator.2.4.5.0\tools\ReportGenerator.exe" "-reports:coverage.xml" "-targetdir:%WORKINGDIR%\reports"
|
||||
COPY /Y %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json.BAK %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json
|
||||
EXIT
|
||||
108
test/CodeCoverage/gulpfile.js
Normal file
108
test/CodeCoverage/gulpfile.js
Normal file
@@ -0,0 +1,108 @@
|
||||
var gulp = require('gulp');
|
||||
//var install = require('gulp-install');;
|
||||
var del = require('del');
|
||||
var request = require('request');
|
||||
var fs = require('fs');
|
||||
var gutil = require('gulp-util');
|
||||
var through = require('through2');
|
||||
var cproc = require('child_process');
|
||||
var os = require('os');
|
||||
|
||||
function nugetRestoreArgs(nupkg, options) {
|
||||
var args = new Array();
|
||||
if (os.platform() != 'win32') {
|
||||
args.push('./nuget.exe');
|
||||
}
|
||||
args.push('restore');
|
||||
args.push(nupkg);
|
||||
|
||||
var withValues = [
|
||||
'source',
|
||||
'configFile',
|
||||
'packagesDirectory',
|
||||
'solutionDirectory',
|
||||
'msBuildVersion'
|
||||
];
|
||||
|
||||
var withoutValues = [
|
||||
'noCache',
|
||||
'requireConsent',
|
||||
'disableParallelProcessing'
|
||||
];
|
||||
|
||||
withValues.forEach(function(prop) {
|
||||
var value = options[prop];
|
||||
if(value) {
|
||||
args.push('-' + prop);
|
||||
args.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
withoutValues.forEach(function(prop) {
|
||||
var value = options[prop];
|
||||
if(value) {
|
||||
args.push('-' + prop);
|
||||
}
|
||||
});
|
||||
|
||||
args.push('-noninteractive');
|
||||
|
||||
return args;
|
||||
};
|
||||
|
||||
function nugetRestore(options) {
|
||||
options = options || {};
|
||||
options.nuget = options.nuget || './nuget.exe';
|
||||
if (os.platform() != 'win32') {
|
||||
options.nuget = 'mono';
|
||||
}
|
||||
|
||||
return through.obj(function(file, encoding, done) {
|
||||
var args = nugetRestoreArgs(file.path, options);
|
||||
cproc.execFile(options.nuget, args, function(err, stdout) {
|
||||
if (err) {
|
||||
throw new gutil.PluginError('gulp-nuget', err);
|
||||
}
|
||||
|
||||
gutil.log(stdout.trim());
|
||||
done(null, file);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
gulp.task('ext:nuget-download', function(done) {
|
||||
if(fs.existsSync('nuget.exe')) {
|
||||
return done();
|
||||
}
|
||||
|
||||
request.get('http://nuget.org/nuget.exe')
|
||||
.pipe(fs.createWriteStream('nuget.exe'))
|
||||
.on('close', done);
|
||||
});
|
||||
|
||||
gulp.task('ext:nuget-restore', function() {
|
||||
|
||||
var options = {
|
||||
configFile: './nuget.config',
|
||||
packagesDirectory: './packages'
|
||||
};
|
||||
|
||||
return gulp.src('./packages.config')
|
||||
.pipe(nugetRestore(options));
|
||||
});
|
||||
|
||||
|
||||
gulp.task('ext:code-coverage', function(done) {
|
||||
cproc.execFile('cmd.exe', [ '/c', 'codecoverage.bat' ], function(err, stdout) {
|
||||
if (err) {
|
||||
throw new gutil.PluginError('ext:code-coverage', err);
|
||||
}
|
||||
|
||||
gutil.log(stdout.trim());
|
||||
});
|
||||
return done();
|
||||
});
|
||||
|
||||
gulp.task('test', gulp.series('ext:nuget-download', 'ext:nuget-restore', 'ext:code-coverage'));
|
||||
|
||||
gulp.task('default', gulp.series('test'));
|
||||
4
test/CodeCoverage/nuget.config
Normal file
4
test/CodeCoverage/nuget.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration >
|
||||
|
||||
</configuration>
|
||||
16
test/CodeCoverage/package.json
Normal file
16
test/CodeCoverage/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "sqltoolsservice",
|
||||
"version": "0.1.0",
|
||||
"description": "SQL Tools Service Layer",
|
||||
"main": "gulpfile.js",
|
||||
"dependencies": {
|
||||
"gulp": "github:gulpjs/gulp#4.0",
|
||||
"del": "^2.2.1",
|
||||
"gulp-hub": "frankwallis/gulp-hub#registry-init",
|
||||
"gulp-install": "^0.6.0",
|
||||
"request": "^2.73.0"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"author": "Microsoft",
|
||||
"license": "MIT"
|
||||
}
|
||||
5
test/CodeCoverage/packages.config
Normal file
5
test/CodeCoverage/packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenCover" version="4.6.519" />
|
||||
<package id="ReportGenerator" version="2.4.5" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user