Skip to content

Commit fca9035

Browse files
committed
Add sp_help code cov
1 parent fed05b3 commit fca9035

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.markdownlint.json
2-
node_modules/*
2+
node_modules/*
3+
package-lock.json

sp_helpme.sql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,22 @@ BEGIN
218218

219219
-- Data Type help (prec/scale only valid for numerics)
220220
SET @SQLString = N'SELECT
221-
[Type_name] = t.name,
222-
[Storage_type] = type_name(system_type_id),
223-
[Length] = max_length,
224-
[Prec] = [precision],
225-
[Scale] = [scale],
226-
[Nullable] = case when is_nullable=1 then @Yes else @No end,
227-
[Default_name] = isnull(object_name(default_object_id), @None),
228-
[Rule_name] = isnull(object_name(rule_object_id), @None),
229-
[Collation] = collation_name,
230-
[ExtendedProperty] = ep.[value]
231-
FROM [sys].[types] AS [t]
232-
LEFT JOIN [sys].[extended_properties] AS [ep] ON [ep].[major_id] = [t].[user_type_id]
233-
AND [ep].[name] = @epname
234-
AND [ep].[minor_id] = 0
235-
AND [ep].[class] = 6
236-
WHERE [user_type_id] = @ObjID';
221+
[Type_name] = t.name,
222+
[Storage_type] = type_name(system_type_id),
223+
[Length] = max_length,
224+
[Prec] = [precision],
225+
[Scale] = [scale],
226+
[Nullable] = case when is_nullable=1 then @Yes else @No end,
227+
[Default_name] = isnull(object_name(default_object_id), @None),
228+
[Rule_name] = isnull(object_name(rule_object_id), @None),
229+
[Collation] = collation_name,
230+
[ExtendedProperty] = ep.[value]
231+
FROM [sys].[types] AS [t]
232+
LEFT JOIN [sys].[extended_properties] AS [ep] ON [ep].[major_id] = [t].[user_type_id]
233+
AND [ep].[name] = @epname
234+
AND [ep].[minor_id] = 0
235+
AND [ep].[class] = 6
236+
WHERE [user_type_id] = @ObjID';
237237
SET @ParmDefinition = N'@ObjID INT, @Yes VARCHAR(5), @No VARCHAR(5), @None VARCHAR(5), @epname SYSNAME';
238238

239239
EXECUTE sp_executesql @SQLString

tests/build/sp_helpme_tests.sql

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,52 @@ EXEC tSQLt.ResultSetFilter 0, @cmd; --Still runs but suppresses undesired output
245245
END;
246246
GO
247247

248+
/*
249+
test that sp_helpme succeeds for a type
250+
*/
251+
CREATE PROCEDURE sp_helpme.[test sp succeeds for a type]
252+
AS
253+
BEGIN
254+
255+
--Build
256+
DECLARE @Type SYSNAME = 'dbo.SizeOptimiserTableType';
257+
DECLARE @cmd NVARCHAR(MAX) = N'EXEC [sp_helpme] ''' + @Type + ''';';
258+
259+
--Assert
260+
EXEC tSQLt.ExpectNoException;
261+
EXEC tSQLt.ResultSetFilter 0, @cmd; --Still runs but suppresses undesired output
262+
263+
END;
264+
GO
265+
266+
/*
267+
test that sp_helpme succeeds for a type
268+
*/
269+
CREATE PROCEDURE sp_helpme.[test sp succeeds for table with schemabound view]
270+
AS
271+
BEGIN
272+
273+
--Build
274+
DECLARE @Table SYSNAME = 'tSQLt.CaptureOutputLog';
275+
DECLARE @cmd NVARCHAR(MAX) = N'EXEC [sp_helpme] ''' + @Table + ''';';
276+
DECLARE @sql NVARCHAR(MAX) = N'
277+
CREATE VIEW dbo.SchemaBoundView
278+
WITH SCHEMABINDING
279+
AS
280+
SELECT [id] FROM tSQLt.CaptureOutputLog;';
281+
282+
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'dbo.SchemaBoundView'))
283+
DROP VIEW dbo.SchemaBoundView;
284+
285+
EXEC sp_executesql @sql;
286+
287+
--Assert
288+
EXEC tSQLt.ExpectNoException;
289+
EXEC tSQLt.ResultSetFilter 0, @cmd; --Still runs but suppresses undesired output
290+
291+
END;
292+
GO
293+
248294
/************************************
249295
End sp_helpme tests
250296
*************************************/

tests/run/localdev_test.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ $TrustedConnection = "yes"
55
$TestPath = "tests\run"
66
$TestBuildPath = "tests\build"
77

8+
# Install TSQLLint
9+
npm install tsqllint -g
810

911
# Install latest versions
1012
Write-Host "Installing scripts..."
11-
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database $Database -InputFile "sp_doc.sql"
12-
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database $Database -InputFile "sp_helpme.sql"
13-
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database $Database -InputFile "sp_sizeoptimiser.sql"
13+
ForEach ($filename in Get-Childitem -Filter "*.sql") {
14+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile $filename.fullname -Verbose | Out-Null
15+
}
16+
17+
# Lint code
18+
Write-Host "Linting scripts..."
19+
tsqllint *.sql
1420

1521
# Install tests
1622
Write-Host "Installing tSQLt Tests..."

0 commit comments

Comments
 (0)