Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fdd7bf1
starting UndoTestDoublesTests.class.sql and related tests
lizbaron Oct 19, 2021
39e0f43
TODO!
lizbaron Oct 19, 2021
f4c4c91
wrote a test which passes. ignored a test which fails. more work requ…
lizbaron Oct 21, 2021
06fc8dc
some refactoring...
lizbaron Oct 22, 2021
d5547ed
add tests to DropClassTests.class.sql to ensure that all object types…
lizbaron Oct 23, 2021
646f3ca
wrote enough tests for DropClassTests.class.sql
lizbaron Oct 23, 2021
6741b90
refactored tSQLt.DropClass.ssp.sql to use tSQLt.Private_GetDropItemCm…
lizbaron Oct 24, 2021
7d33ded
Preparing for a refactor with lots of "suggestions" on how exactly I …
lizbaron Oct 24, 2021
4ec7a9a
moving dropclass target to ps1. exploring multi-line regex in powersh…
lizbaron Oct 26, 2021
6ebbfa5
fighting with powershell and regex (pl. regrets)
lizbaron Oct 27, 2021
5e15203
more progress
mbt1 Oct 27, 2021
a7afa7c
added a parsing challenge
Oct 27, 2021
b7ccbb4
more parsing difficulties
Oct 27, 2021
f46378a
DropClassStatement generation seems to be working
mbt1 Oct 28, 2021
91d05b0
Fixed error'ing test, have one failing test.
lizbaron Oct 28, 2021
9979468
UndoTestDoubles is working. Check out the TODO in UndoTestDoublesTest…
lizbaron Oct 28, 2021
1448b34
123456789012345678901234567890123456789012345678901234567890
lizbaron Oct 28, 2021
0848c6d
testing git.inputValidationLength lulz
lizbaron Oct 28, 2021
2962bfd
Added more Tests/UndoTestDoublesTests.class.sql to make sure that con…
lizbaron Oct 29, 2021
8e861d2
Added tests for ssps and views!
lizbaron Oct 30, 2021
9d4036f
Rewrote a test so that we make sure that we are deleting test doubles…
lizbaron Oct 31, 2021
fe3ba03
Do we make a snapshot or not for FakeFunctions with FakeDataSources? …
lizbaron Oct 31, 2021
5cfd5e3
Removed snapshot'ing from FakeFunction.
lizbaron Nov 1, 2021
82a0a7e
wrote more tests, including one to catch potential future missing tests.
lizbaron Nov 1, 2021
8b181cc
done with UndoTestDoubles for now.
lizbaron Nov 2, 2021
5fca51c
Clean up from Pull Request Review
lizbaron Nov 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Build/CommonFunctionsAndMethods.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,20 @@ Function Remove-ResourceGroup{
Function Get-SnipContent {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][AllowEmptyString()][String[]] $searchArray,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][AllowEmptyString()][string[]]$searchArray,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][String] $startSnipPattern,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][String] $endSnipPattern
)
$outputOn = $false;
(
begin {
$outputOn = $false;
};
process {
$searchArray | ForEach-Object {
if($_ -eq $endSnipPattern) { $outputOn = $false };
if($outputOn) { $_ };
if($_ -eq $startSnipPattern) { $outputOn = $true };
}
);
}
};
end {
};
}
53 changes: 53 additions & 0 deletions Build/CreateDropClassStatement.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$scriptPath = $MyInvocation.MyCommand.Path;
$invocationDir = Split-Path $scriptPath;
$buildPath = $invocationDir +'/';
$tempPath = $invocationDir + '/temp/tSQLtBuild/';
$outputPath = $invocationDir + '/output/tSQLtBuild/';
$sourcePath = $invocationDir + '/../Source/';
$testUtilPath = $invocationDir + '/../TestUtil/';

.($buildPath+"CommonFunctionsAndMethods.ps1");

Log-Output '<#--=======================================================================-->'
Log-Output '<!--======== Start CreateDropClassStatement.ps1 =========-->'
Log-Output '<#--=======================================================================-->'

$DropClassFileContent = Get-Content -path ($sourcePath+"tSQLt.DropClass.ssp.sql");
$GetDropItemCmdFileContent = Get-Content -path ($sourcePath+"tSQLt.Private_GetDropItemCmd.sfn.sql");
$OutputFilePath = $tempPath+"TempDropClass.sql";

$DropClassSnip = ($DropClassFileContent | Get-SnipContent -startSnipPattern "/*SnipStart: CreateDropClassStatement.ps1*/" -endSnipPattern "/*SnipEnd: CreateDropClassStatement.ps1*/");
$DropItemSnip = ($GetDropItemCmdFileContent | Get-SnipContent -startSnipPattern "/*SnipStart: CreateDropClassStatement.ps1*/" -endSnipPattern "/*SnipEnd: CreateDropClassStatement.ps1*/");
$DropItemParamSnip = ($GetDropItemCmdFileContent | Get-SnipContent -startSnipPattern "/*SnipParamStart: CreateDropClassStatement.ps1*/" -endSnipPattern "/*SnipParamEnd: CreateDropClassStatement.ps1*/");

$VariablesString = ($DropItemParamSnip.trim() -join ' ')

$VariableNames = (Select-String '@\S+' -input $VariablesString -AllMatches|ForEach-Object{$_.matches.Value});
#$VariableNames

$DISP1 = ($DropItemSnip | ForEach-Object{
$s=$_;
for($i = 0;$i -lt $VariableNames.count;$i++){
$s=$s -replace $VariableNames[$i], ("($"+($i+1)+")")
};
$s;
});
$DISP2 = $DISP1.trim() -join ' ';

$DropItemSnipPrepared = "("+ $DISP2 + ")";
$RawDropClassStatement = $DropClassSnip -replace 'tSQLt.Private_GetDropItemCmd\s*\(\s*([^,]*)\s*,\s*([^)]*)\s*\)',$DropItemSnipPrepared;

$DropClassStatement = ($RawDropClassStatement.trim()|Where-Object {$_ -ne "" -and $_ -notmatch "^GO(\s.*)?"}) -join ' ';

Set-Content -Path $OutputFilePath -Value $DropClassStatement;

Log-Output '<#--=======================================================================-->'
Log-Output '<!--======== End CreateDropClassStatement.ps1 =========-->'
Log-Output '<#--=======================================================================-->'


<# TODO
--> Test this: Empty File TempDropClass.sql file should throw an error
--> Test this: If the $tempPath does not exist, BuildHelper.exe seems to currently throw an error, but does that stop the build?
--> Test this: If the $sourcePath does not exist, BuildHelper.exe seems to currently throw an error, but does that stop the build?
#>
46 changes: 3 additions & 43 deletions Build/tSQLt.build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,50 +214,10 @@
</target>

<target name="package.create.tSQLtDrop">

<echo message="Starting package.create.tSQLtDrop {===" />

<exec executable="cmd" dir="." failonerror="true">
<arg value="/c"/>
<arg value="BuildHelper.exe"/>
<arg value="../Source/tSQLtDropBuildOrder.txt"/>
<arg value="temp/tSQLtBuild/TempDropClass.sql"/>
<arg value="---Build"/>
<exec dir="." executable="powershell" failonerror="true">
<arg line="-ExecutionPolicy bypass" />
<arg line="-File CreateDropClassStatement.ps1" />
</exec>

<antcall target="replace.in.file">
<param name="replace.file" value="temp/tSQLtBuild/TempDropClass.sql" />
<param name="replace.token" value="tSQLt." />
<param name="replace.value" value="#" />
</antcall>

<antcall target="replace.in.file">
<param name="replace.file" value="temp/tSQLtBuild/TempDropClass.sql" />
<param name="replace.token" value="OBJECT_ID('#" />
<param name="replace.value" value="OBJECT_ID('tempdb..#" />
</antcall>

<antcall target="replace.in.file">
<param name="replace.file" value="temp/tSQLtBuild/TempDropClass.sql" />
<param name="replace.token" value="---Build-" />
<param name="replace.value" value="" />
</antcall>

<antcall target="replace.in.file">
<param name="replace.file" value="temp/tSQLtBuild/TempDropClass.sql" />
<param name="replace.token" value="---Build+" />
<param name="replace.value" value="" />
</antcall>

<replaceregexp match="^(?:[\t ]*(?:\r?\n|\r))+" replace="" flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />
<replaceregexp match="^\s*GO\s*((\r?\n)\s*GO\s*)+$" replace="GO" flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />
<replaceregexp match="(\r?\n)" replace=" " flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />
<replaceregexp match="\s+" replace=" " flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />
<replaceregexp match="GO\s*$" replace="" flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />
<replaceregexp match="^.*?BEGIN" replace="---Build+${line.separator}DECLARE @ClassName NVARCHAR(MAX) ='tSQLt';BEGIN" flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />

<echo message="Starting package.create.tSQLtDrop {===" />

</target>


Expand Down
6 changes: 6 additions & 0 deletions Experiments/Experiments.ssmssqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<AssociatedConnUserName />
<FullPath>NameResolutionResearch.sql</FullPath>
</FileNode>
<FileNode Name="ParsingDisaster.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>ParsingDisaster.sql</FullPath>
</FileNode>
<FileNode Name="RunExternalAccessKeyExistsTests.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
Expand Down
18 changes: 18 additions & 0 deletions Experiments/ParsingDisaster.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--execute, then comment out the line below and execute again
SELECT 1 AS [A
GO
SELECT 0 AS [X]

--/* <-- execute, then delete '--' and execute again
/*Comment*/
SELECT 2
,2.2
--*/SELECT 3 /*
--*/,3.2,'
SELECT 4
,4.2
--' /*
--*/SELECT 5 /*
--*/,5.2 /*
--*/
SELECT 6
6 changes: 5 additions & 1 deletion Source/BuildOrder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ tSQLt._Header.sql
../Build/temp/tSQLtBuild/TempDropClass.sql
tSQLt.schema.sql
tSQLt.TestClass.user.sql
tSQLt.Private_GetDropItemCmd.sfn.sql
tSQLt.DropClass.ssp.sql
tSQLt.Uninstall.ssp.sql
tSQLt.TestClasses.view.sql
Expand Down Expand Up @@ -34,6 +35,7 @@ tSQLtCLR_CreateProcs.sql
tSQLt.Private_PrepareFakeFunctionOutputTable.ssp.sql
tSQLt.TableToText.ssp.sql
tSQLt.Private_RenamedObjectLog.tbl.sql
tSQLt.Private_RenameObject.ssp.sql
tSQLt.Private_MarkObjectBeforeRename.ssp.sql
tSQLt.Private_RenameObjectToUniqueName.ssp.sql
tSQLt.Private_RenameObjectToUniqueNameUsingObjectId.ssp.sql
Expand Down Expand Up @@ -106,4 +108,6 @@ tSQLt.(at)tSQLt_RunOnlyOnHostPlatform.sfn.sql
tSQLt.RemoveExternalAccessKey.ssp.sql
tSQLt.InstallExternalAccessKey.ssp.sql
tSQLt.Private_InstallationInfo.sfn.sql
tSQLt._Footer.sql
tSQLt.UndoSingleTestDouble.ssp.sql
tSQLt.UndoTestDoubles.ssp.sql
tSQLt._Footer.sql
30 changes: 30 additions & 0 deletions Source/Source.ssmssqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
<AssociatedConnUserName />
<FullPath>tSQLt.Private_GetDefaultConstraintDefinition.sfn.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Private_GetDropItemCmd.sfn.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>tSQLt.Private_GetDropItemCmd.sfn.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Private_GetForeignKeyDefinition.sfn.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
Expand Down Expand Up @@ -414,6 +420,12 @@
<AssociatedConnUserName />
<FullPath>tSQLt.Private_NullCellTable.tbl.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Private_PrepareFakeFunctionOutputTable.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>tSQLt.Private_PrepareFakeFunctionOutputTable.ssp.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Private_ProcessTestAnnotations.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
Expand All @@ -438,6 +450,12 @@
<AssociatedConnUserName />
<FullPath>tSQLt.Private_RemoveSchemaBoundReferences.ssp.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Private_RenameObject.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>tSQLt.Private_RenameObject.ssp.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Private_RenameObjectToUniqueName.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
Expand Down Expand Up @@ -636,6 +654,18 @@
<AssociatedConnUserName />
<FullPath>tSQLt.Tests.view.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.UndoSingleTestDouble.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>tSQLt.UndoSingleTestDouble.ssp.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.UndoTestDoubles.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>tSQLt.UndoTestDoubles.ssp.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt.Uninstall.ssp.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
Expand Down
65 changes: 31 additions & 34 deletions Source/tSQLt.DropClass.ssp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,60 @@ CREATE PROCEDURE tSQLt.DropClass
@ClassName NVARCHAR(MAX)
AS
BEGIN
/*SnipStart: CreateDropClassStatement.ps1*/
DECLARE @Cmd NVARCHAR(MAX);

WITH ObjectInfo(name, type) AS
WITH ObjectInfo(FullName, ItemType) AS
(
SELECT QUOTENAME(SCHEMA_NAME(O.schema_id))+'.'+QUOTENAME(O.name) , O.type
SELECT
QUOTENAME(SCHEMA_NAME(O.schema_id))+'.'+QUOTENAME(O.name),
O.type
FROM sys.objects AS O
WHERE O.schema_id = SCHEMA_ID(@ClassName)
),
TypeInfo(name) AS
TypeInfo(FullName, ItemType) AS
(
SELECT QUOTENAME(SCHEMA_NAME(T.schema_id))+'.'+QUOTENAME(T.name)
SELECT
QUOTENAME(SCHEMA_NAME(T.schema_id))+'.'+QUOTENAME(T.name),
'type'
FROM sys.types AS T
WHERE T.schema_id = SCHEMA_ID(@ClassName)
),
XMLSchemaInfo(name) AS
XMLSchemaInfo(FullName, ItemType) AS
(
SELECT QUOTENAME(SCHEMA_NAME(XSC.schema_id))+'.'+QUOTENAME(XSC.name)
SELECT
QUOTENAME(SCHEMA_NAME(XSC.schema_id))+'.'+QUOTENAME(XSC.name),
'xml_schema_collection'
FROM sys.xml_schema_collections AS XSC
WHERE XSC.schema_id = SCHEMA_ID(@ClassName)
),
DropStatements(no,cmd) AS
SchemaInfo(FullName, ItemType) AS
(
SELECT 10,
'DROP ' +
CASE type WHEN 'P' THEN 'PROCEDURE'
WHEN 'PC' THEN 'PROCEDURE'
WHEN 'U' THEN 'TABLE'
WHEN 'IF' THEN 'FUNCTION'
WHEN 'TF' THEN 'FUNCTION'
WHEN 'FN' THEN 'FUNCTION'
WHEN 'FT' THEN 'FUNCTION'
WHEN 'V' THEN 'VIEW'
END +
' ' +
name +
';'
SELECT
QUOTENAME(S.name),
'schema'
FROM sys.schemas AS S
WHERE S.schema_id = SCHEMA_ID(PARSENAME(@ClassName,1))
),
DropStatements(no,FullName,ItemType) AS
(
SELECT 10, FullName, ItemType
FROM ObjectInfo
UNION ALL
SELECT 20,
'DROP TYPE ' +
name +
';'
SELECT 20, FullName, ItemType
FROM TypeInfo
UNION ALL
SELECT 30,
'DROP XML SCHEMA COLLECTION ' +
name +
';'
SELECT 30, FullName, ItemType
FROM XMLSchemaInfo
UNION ALL
SELECT 10000,'DROP SCHEMA ' + QUOTENAME(name) +';'
FROM sys.schemas
WHERE schema_id = SCHEMA_ID(PARSENAME(@ClassName,1))
SELECT 10000, FullName, ItemType
FROM SchemaInfo
),
StatementBlob(xml)AS
(
SELECT cmd [text()]
FROM DropStatements
SELECT GDIC.cmd [text()]
FROM DropStatements DS
CROSS APPLY tSQLt.Private_GetDropItemCmd(DS.FullName, DS.ItemType) GDIC
ORDER BY no
FOR XML PATH(''), TYPE
)
Expand All @@ -71,5 +67,6 @@ BEGIN

EXEC(@Cmd);
END;
/*SnipEnd: CreateDropClassStatement.ps1*/
---Build-
GO
25 changes: 17 additions & 8 deletions Source/tSQLt.Private_CreateFakeFunction.ssp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,24 @@ BEGIN
BEGIN
EXEC('CREATE FUNCTION '+@FunctionName+'('+@ParameterList+') RETURNS '+@ReturnType+' AS BEGIN RETURN '+@FakeFunctionName+'('+@ParameterCallList+');END;');
END
ELSE IF (@FakeDataSource IS NOT NULL)
ELSE
BEGIN
DECLARE @newTbleName NVARCHAR(MAX);
EXEC tSQLt.Private_PrepareFakeFunctionOutputTable @FakeDataSource, @newTbleName OUTPUT;
EXEC ('CREATE FUNCTION '+@FunctionName+'('+@ParameterList+') RETURNS TABLE AS RETURN ( SELECT * FROM '+@newTbleName+');');
END
ELSE
BEGIN
EXEC('CREATE FUNCTION '+@FunctionName+'('+@ParameterList+') RETURNS TABLE AS RETURN SELECT * FROM '+@FakeFunctionName+'('+@ParameterCallList+');');
DECLARE @cmd NVARCHAR(MAX);
IF (@FakeDataSource IS NOT NULL)
BEGIN
SET @cmd =
CASE
WHEN OBJECT_ID(@FakeDataSource) IS NOT NULL THEN 'SELECT * FROM '+@FakeDataSource
WHEN @FakeDataSource LIKE '(%)%(%)' THEN 'SELECT * FROM '+@FakeDataSource
ELSE @FakeDataSource
END;
END
ELSE
BEGIN
SET @cmd = 'SELECT * FROM '+@FakeFunctionName+'('+@ParameterCallList+')';
END;
SET @cmd = 'CREATE FUNCTION '+@FunctionName+'('+@ParameterList+') RETURNS TABLE AS RETURN '+@cmd+';'
EXEC(@cmd);
END;
END;
GO
Loading