forked from tSQLt-org/tSQLt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtSQLtclr_test.class.sql
More file actions
187 lines (138 loc) · 5.22 KB
/
Copy pathtSQLtclr_test.class.sql
File metadata and controls
187 lines (138 loc) · 5.22 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
Copyright 2011 tSQLt
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
EXEC tSQLt.NewTestClass 'tSQLtclr_test';
GO
CREATE PROC tSQLtclr_test.[test CaptureOutput places the console output of a command into the CaptureOutputLog]
AS
BEGIN
EXEC tSQLt.CaptureOutput 'print ''Catch Me if You Can!''';
SELECT OutputText
INTO #actual
FROM tSQLt.CaptureOutputLog;
SELECT TOP(0) *
INTO #expected
FROM #actual;
INSERT INTO #expected(OutputText)VALUES('Catch Me if You Can!' + CHAR(13) + CHAR(10));
EXEC tSQLt.AssertEqualsTable '#expected','#actual';
END;
GO
CREATE PROC tSQLtclr_test.[test CaptureOutput, called with a command that does not print, results in no messages captured]
AS
BEGIN
EXEC tSQLt.CaptureOutput 'DECLARE @i INT;';
SELECT OutputText
INTO #actual
FROM tSQLt.CaptureOutputLog;
SELECT TOP(0) *
INTO #expected
FROM #actual;
INSERT INTO #expected(OutputText)VALUES(NULL);
EXEC tSQLt.AssertEqualsTable '#expected','#actual';
END;
GO
CREATE PROC tSQLtclr_test.[test CaptureOutput captures output that happens in between resultsets]
AS
BEGIN
EXEC tSQLt.CaptureOutput 'PRINT ''AAAAA'';SELECT 1 a;PRINT ''BBBBB'';SELECT 1 b;PRINT ''CCCCC'';';
DECLARE @OutputText NVARCHAR(MAX);
SELECT @OutputText = OutputText FROM tSQLt.CaptureOutputLog;
IF(@OutputText NOT LIKE 'AAAAA%BBBBB%CCCCC%')
EXEC tSQLt.Fail 'Unexpected OutputText Captured! Expected to match ''AAAAA%BBBBB%CCCCC%'', was: ''',@OutputText,'''!';
END;
GO
CREATE PROC tSQLtclr_test.[test CaptureOutput can be executed twice with the different output]
AS
BEGIN
EXEC tSQLt.CaptureOutput 'print ''Catch Me if You Can!''';
EXEC tSQLt.CaptureOutput 'print ''Oh, you got me!!''';
SELECT Id+0 Id,OutputText
INTO #actual
FROM tSQLt.CaptureOutputLog;
SELECT TOP(0) *
INTO #expected
FROM #actual;
INSERT INTO #expected(Id,OutputText)VALUES(1,'Catch Me if You Can!' + CHAR(13) + CHAR(10) );
INSERT INTO #expected(Id,OutputText)VALUES(2,'Oh, you got me!!' + CHAR(13) + CHAR(10) );
EXEC tSQLt.AssertEqualsTable '#expected','#actual';
END;
GO
CREATE PROC tSQLtclr_test.[test CaptureOutput propogates an error]
AS
BEGIN
DECLARE @msg NVARCHAR(MAX);
SELECT @msg = 'No error message';
BEGIN TRY
EXEC tSQLt.CaptureOutput 'RAISERROR(''hello'', 16, 10);';
END TRY
BEGIN CATCH
SET @msg = ERROR_MESSAGE();
END CATCH
IF @msg NOT LIKE '%hello%'
EXEC tSQLt.Fail 'Expected the error message to be propogated up to SQL, but the message was: ', @msg;
END;
GO
CREATE PROC tSQLtclr_test.[test CaptureOutput can capture raiserror output with low severity]
AS
BEGIN
EXEC tSQLt.CaptureOutput 'RAISERROR(''Catch Me if You Can!'', 0, 1);';
SELECT OutputText
INTO #actual
FROM tSQLt.CaptureOutputLog;
SELECT TOP(0) *
INTO #expected
FROM #actual;
INSERT INTO #expected(OutputText)VALUES('Catch Me if You Can!' + CHAR(13) + CHAR(10));
EXEC tSQLt.AssertEqualsTable '#expected','#actual';
END;
GO
CREATE PROC tSQLtclr_test.[test SuppressOutput causes no output to be produced]
AS
BEGIN
EXEC tSQLt.CaptureOutput 'EXEC tSQLt.SuppressOutput ''print ''''hello'''';'';';
SELECT OutputText
INTO #actual
FROM tSQLt.CaptureOutputLog;
SELECT TOP(0) *
INTO #expected
FROM #actual;
INSERT INTO #expected(OutputText)VALUES(NULL);
EXEC tSQLt.AssertEqualsTable '#expected','#actual';
END;
GO
CREATE PROC tSQLtclr_test.[test tSQLt.Info.Version and tSQLt.Private::info() return the same value]
AS
BEGIN
DECLARE @tSQLtVersion NVARCHAR(MAX); SET @tSQLtVersion = (SELECT Version FROM tSQLt.Info());
DECLARE @tSQLtPrivateVersion NVARCHAR(MAX); SET @tSQLtPrivateVersion = (SELECT tSQLt.Private::Info());
EXEC tSQLt.AssertEqualsString @tSQLtVersion, @tSQLtPrivateVersion;
END;
GO
CREATE PROC tSQLtclr_test.[test tSQLt.Info.ClrVersion and tSQLt.Private::info() return the same value]
AS
BEGIN
DECLARE @tSQLtClrVersion NVARCHAR(MAX); SET @tSQLtClrVersion = (SELECT ClrVersion FROM tSQLt.Info());
DECLARE @tSQLtPrivateVersion NVARCHAR(MAX); SET @tSQLtPrivateVersion = (SELECT tSQLt.Private::Info());
EXEC tSQLt.AssertEqualsString @tSQLtClrVersion, @tSQLtPrivateVersion;
END;
GO
CREATE PROC tSQLtclr_test.[test tSQLt.Info.ClrVersion uses tSQLt.Private::info()]
AS
BEGIN
DECLARE @tSQLtInfoText NVARCHAR(MAX); SET @tSQLtInfoText = OBJECT_DEFINITION(OBJECT_ID('tSQLt.Info'));
IF( @tSQLtInfoText NOT LIKE '%ClrVersion = (SELECT tSQLt.Private::Info())%')
BEGIN
EXEC tSQLt.Fail 'Expected @tSQLtInfoText LIKE ''ClrVersion = (SELECT tSQLt.Private::Info())'' but was:',@tSQLtInfoText;
END;
END;
GO
--ROLLBACK