|
1 | 1 | import assert from "assert"; |
2 | | -import os from "os"; |
3 | 2 | import { Uri, workspace } from "vscode"; |
4 | 3 | import { TestSuite } from "."; |
5 | 4 | import IBMi from "../api/IBMi"; |
6 | 5 | import { Tools } from "../api/Tools"; |
7 | 6 | import { getMemberUri } from "../filesystems/qsys/QSysFs"; |
8 | 7 | import { instance } from "../instantiate"; |
9 | | -import { IBMiObject } from "../typings"; |
10 | 8 | import path from "path"; |
11 | 9 |
|
12 | 10 | const contents = { |
@@ -56,41 +54,6 @@ export const EncodingSuite: TestSuite = { |
56 | 54 | }, |
57 | 55 |
|
58 | 56 | tests: [ |
59 | | - { |
60 | | - name: `Prove that input strings are messed up by CCSID`, test: async () => { |
61 | | - const connection = instance.getConnection(); |
62 | | - let howManyTimesItMessedUpTheResult = 0; |
63 | | - |
64 | | - for (const strCcsid in contents) { |
65 | | - const data = contents[strCcsid as keyof typeof contents].join(``); |
66 | | - |
67 | | - // Note that it always works with the buffer! |
68 | | - const sqlA = `select ? as THEDATA from sysibm.sysdummy1`; |
69 | | - const resultA = await connection?.runSQL(sqlA, { fakeBindings: [data], forceSafe: true }); |
70 | | - assert.ok(resultA?.length); |
71 | | - |
72 | | - const sqlB = `select '${data}' as THEDATA from sysibm.sysdummy1`; |
73 | | - const resultB = await connection?.runSQL(sqlB, { forceSafe: true }); |
74 | | - assert.ok(resultB?.length); |
75 | | - |
76 | | - assert.strictEqual(resultA![0].THEDATA, data); |
77 | | - if (resultB![0].THEDATA !== data) { |
78 | | - howManyTimesItMessedUpTheResult++; |
79 | | - } |
80 | | - } |
81 | | - |
82 | | - assert.ok(howManyTimesItMessedUpTheResult); |
83 | | - } |
84 | | - }, |
85 | | - { |
86 | | - name: `Compare Unicode to EBCDIC successfully`, test: async () => { |
87 | | - const connection = instance.getConnection(); |
88 | | - |
89 | | - const sql = `select table_name, table_owner from qsys2.systables where table_schema = ? and table_name = ?`; |
90 | | - const result = await connection?.runSQL(sql, { fakeBindings: [`QSYS2`, `SYSCOLUMNS`] }); |
91 | | - assert.ok(result?.length); |
92 | | - } |
93 | | - }, |
94 | 57 | { |
95 | 58 | name: `Files and directories with spaces`, test: async () => { |
96 | 59 | const connection = instance.getConnection()!; |
@@ -129,55 +92,6 @@ export const EncodingSuite: TestSuite = { |
129 | 92 | }); |
130 | 93 | } |
131 | 94 | }, |
132 | | - { |
133 | | - name: `Run variants through shells`, test: async () => { |
134 | | - const connection = instance.getConnection(); |
135 | | - |
136 | | - const text = `Hello${connection?.variantChars.local}world`; |
137 | | - const basicCommandA = `echo "${IBMi.escapeForShell(text)}"`; |
138 | | - const basicCommandB = `echo '${text}'`; |
139 | | - const basicCommandC = `echo 'abc'\\''123'`; |
140 | | - const printEscapeChar = `echo "\\\\"`; |
141 | | - const setCommand = `set`; |
142 | | - |
143 | | - const setResult = await connection?.sendQsh({ command: setCommand }); |
144 | | - |
145 | | - const qshEscapeResult = await connection?.sendQsh({ command: printEscapeChar }); |
146 | | - const paseEscapeResult = await connection?.sendCommand({ command: printEscapeChar }); |
147 | | - |
148 | | - console.log(qshEscapeResult?.stdout); |
149 | | - console.log(paseEscapeResult?.stdout); |
150 | | - |
151 | | - const qshTextResultA = await connection?.sendQsh({ command: basicCommandA }); |
152 | | - const paseTextResultA = await connection?.sendCommand({ command: basicCommandA }); |
153 | | - |
154 | | - const qshTextResultB = await connection?.sendQsh({ command: basicCommandB }); |
155 | | - const paseTextResultB = await connection?.sendCommand({ command: basicCommandB }); |
156 | | - |
157 | | - const qshTextResultC = await connection?.sendQsh({ command: basicCommandC }); |
158 | | - const paseTextResultC = await connection?.sendCommand({ command: basicCommandC }); |
159 | | - |
160 | | - assert.strictEqual(paseEscapeResult?.stdout, `\\`); |
161 | | - assert.strictEqual(qshTextResultA?.stdout, text); |
162 | | - assert.strictEqual(paseTextResultA?.stdout, text); |
163 | | - assert.strictEqual(qshTextResultB?.stdout, text); |
164 | | - assert.strictEqual(paseTextResultB?.stdout, text); |
165 | | - } |
166 | | - }, |
167 | | - { |
168 | | - name: `streamfileResolve with dollar`, test: async () => { |
169 | | - const connection = instance.getConnection()!; |
170 | | - |
171 | | - await connection.withTempDirectory(async tempDir => { |
172 | | - const tempFile = path.posix.join(tempDir, `$hello`); |
173 | | - await connection.content.createStreamFile(tempFile); |
174 | | - |
175 | | - const resolved = await connection.content.streamfileResolve([tempFile], [`/`]); |
176 | | - |
177 | | - assert.strictEqual(resolved, tempFile); |
178 | | - }); |
179 | | - } |
180 | | - }, |
181 | 95 | ...SHELL_CHARS.map(char => ({ |
182 | 96 | name: `Test streamfiles with shell character ${char}`, test: async () => { |
183 | 97 | const connection = instance.getConnection()!; |
@@ -256,128 +170,6 @@ export const EncodingSuite: TestSuite = { |
256 | 170 | assert.ok(fileContent.includes(`Woah`)); |
257 | 171 | } |
258 | 172 | })), |
259 | | - { |
260 | | - name: "Listing objects with variants", |
261 | | - test: async () => { |
262 | | - const connection = instance.getConnection(); |
263 | | - const content = instance.getConnection()?.content; |
264 | | - if (connection && content) { |
265 | | - const tempLib = connection.config?.tempLibrary!; |
266 | | - const ccsid = connection.getCcsid(); |
267 | | - |
268 | | - let library = `TESTLIB${connection.variantChars.local}`; |
269 | | - let skipLibrary = false; |
270 | | - const sourceFile = `${connection.variantChars.local}TESTFIL`; |
271 | | - const dataArea = `TSTDTA${connection.variantChars.local}`; |
272 | | - const members: string[] = []; |
273 | | - |
274 | | - for (let i = 0; i < 5; i++) { |
275 | | - members.push(`TSTMBR${connection.variantChars.local}${i}`); |
276 | | - } |
277 | | - |
278 | | - await connection.runCommand({ command: `DLTLIB LIB(${library})`, noLibList: true }); |
279 | | - |
280 | | - const crtLib = await connection.runCommand({ command: `CRTLIB LIB(${library}) TYPE(*PROD)`, noLibList: true }); |
281 | | - if (Tools.parseMessages(crtLib.stderr).findId("CPD0032")) { |
282 | | - //Not authorized: carry on, skip library name test |
283 | | - library = tempLib; |
284 | | - skipLibrary = true |
285 | | - } |
286 | | - |
287 | | - let commands: string[] = []; |
288 | | - |
289 | | - commands.push(`CRTSRCPF FILE(${library}/${sourceFile}) RCDLEN(112) CCSID(${ccsid})`); |
290 | | - for (const member of members) { |
291 | | - commands.push(`ADDPFM FILE(${library}/${sourceFile}) MBR(${member}) SRCTYPE(TXT) TEXT('Test ${member}')`); |
292 | | - } |
293 | | - |
294 | | - commands.push(`CRTDTAARA DTAARA(${library}/${dataArea}) TYPE(*CHAR) LEN(50) VALUE('hi')`); |
295 | | - |
296 | | - // runCommandsWithCCSID proves that using variant characters in runCommand works! |
297 | | - const result = await runCommandsWithCCSID(connection, commands, ccsid); |
298 | | - assert.strictEqual(result.code, 0); |
299 | | - |
300 | | - if (!skipLibrary) { |
301 | | - const [expectedLibrary] = await content.getLibraries({ library }); |
302 | | - assert.ok(expectedLibrary); |
303 | | - assert.strictEqual(library, expectedLibrary.name); |
304 | | - |
305 | | - const validated = await connection.content.validateLibraryList([tempLib, library]); |
306 | | - assert.strictEqual(validated.length, 0); |
307 | | - |
308 | | - const libl = await content.getLibraryList([library]); |
309 | | - assert.strictEqual(libl.length, 1); |
310 | | - assert.strictEqual(libl[0].name, library); |
311 | | - } |
312 | | - |
313 | | - const checkFile = (expectedObject: IBMiObject) => { |
314 | | - assert.ok(expectedObject); |
315 | | - assert.ok(expectedObject.sourceFile, `${expectedObject.name} not a source file`); |
316 | | - assert.strictEqual(expectedObject.name, sourceFile); |
317 | | - assert.strictEqual(expectedObject.library, library); |
318 | | - }; |
319 | | - |
320 | | - const nameFilter = await content.getObjectList({ library, types: ["*ALL"], object: `${connection.variantChars.local[0]}*` }); |
321 | | - assert.strictEqual(nameFilter.length, 1); |
322 | | - assert.ok(nameFilter.some(obj => obj.library === library && obj.type === `*FILE` && obj.name === sourceFile)); |
323 | | - |
324 | | - const objectList = await content.getObjectList({ library, types: ["*ALL"] }); |
325 | | - assert.ok(objectList.some(obj => obj.library === library && obj.type === `*FILE` && obj.name === sourceFile && obj.sourceFile === true)); |
326 | | - assert.ok(objectList.some(obj => obj.library === library && obj.type === `*DTAARA` && obj.name === dataArea)); |
327 | | - |
328 | | - const expectedMembers = await content.getMemberList({ library, sourceFile }); |
329 | | - assert.ok(expectedMembers); |
330 | | - assert.ok(expectedMembers.every(member => members.find(m => m === member.name && member.text?.includes(m)))); |
331 | | - |
332 | | - const sourceFilter = await content.getObjectList({ library, types: ["*SRCPF"], object: `${connection.variantChars.local[0]}*` }); |
333 | | - assert.strictEqual(sourceFilter.length, 1); |
334 | | - assert.ok(sourceFilter.some(obj => obj.library === library && obj.type === `*FILE` && obj.name === sourceFile)); |
335 | | - |
336 | | - const [expectDataArea] = await content.getObjectList({ library, object: dataArea, types: ["*DTAARA"] }); |
337 | | - assert.strictEqual(expectDataArea.name, dataArea); |
338 | | - assert.strictEqual(expectDataArea.library, library); |
339 | | - assert.strictEqual(expectDataArea.type, `*DTAARA`); |
340 | | - |
341 | | - const [expectedSourceFile] = await content.getObjectList({ library, object: sourceFile, types: ["*SRCPF"] }); |
342 | | - checkFile(expectedSourceFile); |
343 | | - |
344 | | - } |
345 | | - } |
346 | | - }, |
347 | | - { |
348 | | - name: `Library list supports dollar sign variant`, test: async () => { |
349 | | - const connection = instance.getConnection()!; |
350 | | - const library = `TEST${connection.variantChars.local}LIB`; |
351 | | - const sourceFile = `TEST${connection.variantChars.local}FIL`; |
352 | | - const member = `TEST${connection.variantChars.local}MBR`; |
353 | | - const ccsid = connection.getCcsid(); |
354 | | - |
355 | | - if (library.includes(`$`)) { |
356 | | - await connection.runCommand({ command: `DLTLIB LIB(${library})`, noLibList: true }); |
357 | | - |
358 | | - const crtLib = await connection.runCommand({ command: `CRTLIB LIB(${library}) TYPE(*PROD)`, noLibList: true }); |
359 | | - if (Tools.parseMessages(crtLib.stderr).findId("CPD0032")) { |
360 | | - return; |
361 | | - } |
362 | | - |
363 | | - const createSourceFileCommand = await connection.runCommand({ command: `CRTSRCPF FILE(${library}/${sourceFile}) RCDLEN(112) CCSID(${ccsid})`, noLibList: true }); |
364 | | - assert.strictEqual(createSourceFileCommand.code, 0); |
365 | | - |
366 | | - const addPf = await connection.runCommand({ command: `ADDPFM FILE(${library}/${sourceFile}) MBR(${member}) SRCTYPE(TXT)`, noLibList: true }); |
367 | | - assert.strictEqual(addPf.code, 0); |
368 | | - |
369 | | - await connection.content.uploadMemberContent(undefined, library, sourceFile, member, [`**free`, `dsply 'Hello world';`, `return;`].join(`\n`)); |
370 | | - |
371 | | - // Ensure program compiles with dollar sign in current library |
372 | | - const compileResultA = await connection.runCommand({ command: `CRTBNDRPG PGM(${library}/${member}) SRCFILE(${library}/${sourceFile}) SRCMBR(${member})`, env: {'&CURLIB': library} }); |
373 | | - assert.strictEqual(compileResultA.code, 0); |
374 | | - |
375 | | - // Ensure program compiles with dollar sign in current library |
376 | | - const compileResultB = await connection.runCommand({ command: `CRTBNDRPG PGM(${library}/${member}) SRCFILE(${library}/${sourceFile}) SRCMBR(${member})`, env: {'&LIBL': library} }); |
377 | | - assert.strictEqual(compileResultB.code, 0); |
378 | | - } |
379 | | - } |
380 | | - }, |
381 | 173 | { |
382 | 174 | name: `Variant character in source names and commands`, test: async () => { |
383 | 175 | // CHGUSRPRF X CCSID(284) CNTRYID(ES) LANGID(ESP) |
|
0 commit comments