This repository was archived by the owner on Mar 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcs_srvpgm.test.ts
More file actions
158 lines (121 loc) · 7.38 KB
/
cs_srvpgm.test.ts
File metadata and controls
158 lines (121 loc) · 7.38 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
import { beforeAll, describe, expect, test } from 'vitest';
import { Targets } from '../src/targets'
import { MakeProject } from '../src/builders/make';
import { setupFixture } from './fixtures/projects';
import { ReadFileSystem } from '../src/readFileSystem';
import { BobProject } from '../src/builders/bob';
import path from 'path';
import { ProjectActions } from '../src/builders/actions';
describe(`pseudo tests`, () => {
const project = setupFixture(`cs_srvpgm`);
const fs = new ReadFileSystem();
const targets = new Targets(project.cwd, fs);
let make: MakeProject;
let actions: ProjectActions
beforeAll(async () => {
project.setup();
await targets.loadProject({additionalExtensions: [`rpgleinc`]});
expect(targets.getResolvedObjects().length).toBe(13);
expect(targets.getResolvedObjectsByFileExtension(`rpgleinc`).length).toBe(0);
targets.resolveBinder();
expect(targets.getTargets().length).toBeGreaterThan(0);
make = new MakeProject(project.cwd, targets, fs);
await make.setupSettings();
actions = new ProjectActions(targets, fs);
await actions.loadAllActions();
});
test(`That test files are understood`, () => {
expect(targets).toBeDefined();
expect(targets.binderRequired()).toBeFalsy();
const testModule = targets.getTarget({systemName: `TEMPTEST`, type: `MODULE`});
expect(testModule).toBeDefined();
expect(testModule.deps.length).toBe(3);
expect(testModule.deps.find(f => f.systemName === `EMPLOYEE`)).toBeDefined();
expect(testModule.deps.find(f => f.systemName === `DEPARTMENT`)).toBeDefined();
expect(testModule.deps.find(f => f.systemName === `EMPDET` && f.type === `MODULE`)).toBeDefined();
});
test('Imports are resolved from include files (cross-platform path fix)', () => {
// This test validates the fix for the path separator bug where imports
// from .rpgleinc files were not being resolved in the VS Code extension
const empdet = targets.getTarget({systemName: `EMPDET`, type: `MODULE`});
expect(empdet).toBeDefined();
// The EMPDET module should have imports from qrpgleref/empdet.rpgleinc
// This was failing before the fix because globalEntryIsValid() couldn't
// match paths with different separators (/ vs \)
expect(empdet.imports).toBeDefined();
expect(empdet.imports.length).toBe(2);
expect(empdet.imports).toContain('GETDEPTDETAIL');
expect(empdet.imports).toContain('GETEMPLOYEEDETAIL');
});
test('Deps are picked up for the module', () => {
const empdet = targets.getTarget({systemName: `EMPDET`, type: `MODULE`});
expect(empdet).toBeDefined();
expect(empdet.deps.length).toBe(2);
expect(empdet.deps.find(f => f.systemName === `EMPLOYEE`)).toBeDefined();
expect(empdet.deps.find(f => f.systemName === `DEPARTMENT`)).toBeDefined();
const allRequirements = targets.getRequiredChildren([empdet]);
expect(allRequirements.length).toBe(3);
expect(allRequirements.find(f => f.systemName === `EMPLOYEE` && f.type === `FILE`)).toBeDefined();
expect(allRequirements.find(f => f.systemName === `DEPARTMENT` && f.type === `FILE`)).toBeDefined();
expect(allRequirements.find(f => f.systemName === `EMPDET` && f.type === `MODULE`)).toBeDefined();
const employees = targets.getTarget({systemName: `EMPLOYEES`, type: `PGM`});
expect(employees).toBeDefined();
expect(employees.deps.length).toBe(4);
expect(employees.deps.find(f => f.systemName === `EMPLOYEES` && f.type === `MODULE`)).toBeDefined();
expect(employees.deps.find(f => f.systemName === `EMPDET` && f.type === `MODULE`)).toBeDefined();
expect(employees.deps.find(f => f.systemName === `EMPS` && f.type === `FILE`)).toBeDefined();
expect(employees.deps.find(f => f.systemName === `EMPLOYEE` && f.type === `FILE`)).toBeDefined();
const requiredForEmployees = targets.getRequiredChildren([employees]);
expect(requiredForEmployees.length).toBe(6);
expect(requiredForEmployees.find(f => f.systemName === `EMPLOYEES` && f.type === `PGM`)).toBeDefined();
expect(requiredForEmployees.find(f => f.systemName === `EMPDET` && f.type === `MODULE`)).toBeDefined();
expect(requiredForEmployees.find(f => f.systemName === `EMPLOYEE` && f.type === `FILE`)).toBeDefined();
expect(requiredForEmployees.find(f => f.systemName === `DEPARTMENT` && f.type === `FILE`)).toBeDefined();
expect(requiredForEmployees.find(f => f.systemName === `EMPS` && f.type === `FILE`)).toBeDefined();
expect(requiredForEmployees.find(f => f.systemName === `EMPDET` && f.type === `MODULE`)).toBeDefined
});
test('ibmi-bob rules', () => {
const bobProject = new BobProject(targets);
const files = bobProject.createRules();
expect(files[`Rules.mk`]).toBeDefined();
expect(files[`Rules.mk`]).toBe(`SUBDIRS = qddssrc qrpglesrc qtestsrc`);
expect(files[path.join(`qtestsrc`, `Rules.mk`)]).toBe(`TEMPTEST.MODULE: emptest.test.sqlrpgle qrpgleref/empdet.rpgleinc EMPLOYEE.FILE DEPARTMENT.FILE EMPDET.MODULE`)
expect(files[path.join(`qrpglesrc`, `Rules.mk`)]).toContain(`EMPLOYEES.MODULE: employees.pgm.sqlrpgle qrpgleref/constants.rpgleinc qrpgleref/empdet.rpgleinc`);
expect(files[path.join(`qrpglesrc`, `Rules.mk`)]).toContain(`EMPLOYEES.PGM: EMPLOYEE.FILE EMPS.FILE EMPDET.MODULE EMPLOYEES.MODULE`);
expect(files[path.join(`qrpglesrc`, `Rules.mk`)]).not.toContain(`EMPDET.SRVPGM`); // Ensure no service program is created
});
test('makefile', async () => {
const makefile = new MakeProject(targets.getCwd(), targets, fs);
makefile.useActions();
await makefile.setupSettings();
const contents = makefile.getMakefile().join(`\n`);
expect(contents).toContain(`$(PREPATH)/EMPLOYEES.PGM:`);
expect(contents).toContain(`system "CRTPGM PGM($(BIN_LIB)/EMPLOYEES) ENTMOD(EMPLOYEES) MODULE(EMPDET EMPLOYEES) TGTRLS(*CURRENT) BNDDIR($(APP_BNDDIR)) ACTGRP(*NEW)" > .logs/employees.splf`);
expect(contents).not.toContain(`EMPDET.SRVPGM`); // Ensure no service program is created
expect(contents).toContain(`EMPDET.MODULE`);
expect(contents).toContain(`CRTSQLRPGI OBJ($(BIN_LIB)/EMPDET) SRCSTMF('qrpglesrc/empdet.sqlrpgle') COMMIT(*NONE) DBGVIEW(*SOURCE) COMPILEOPT('TGTCCSID(*JOB)') RPGPPOPT(*LVL2) OPTION(*EVENTF) OBJTYPE(*MODULE)`);
// As picked up from the actions.json
expect(contents).toContain(`system "CRTBNDRPG NAME(mypgm) THEPARM('qrpglesrc/mypgm.pgm.rpgle')" > .logs/mypgm.splf`);
});
test('there are actions', async () => {
expect(actions.getActionPaths.length).toBe(2);
expect(actions.getActionPaths).toContain(`actions.json`);
expect(actions.getActionPaths).toContain(path.join(`qddssrc`, `actions.json`));
});
test('correct actions get detected', async () => {
const ddsSrcA = path.join(`qddssrc`, `popemp.sql`);
const ddsSrcB = path.join(`qsqlsrc`, `popemp.sql`);
// Finds the actions file `qddssrc`
const actionA = actions.getActionForPath(ddsSrcA);
// Finds the project actions file
const actionB = actions.getActionForPath(ddsSrcB);
expect(actionA).toBeDefined();
expect(actionA?.command).toBe(`RUNSQLSTM SRCSTMF('&RELATIVEPATH')`);
expect(actionB).toBeDefined();
expect(actionB?.command).toBe(`RUNSQL SRCSTMF('&RELATIVEPATH')`);
const rpgleSrc = path.join(`qrpglesrc`, `mypgm.pgm.rpgle`);
const actionC = actions.getActionForPath(rpgleSrc);
expect(actionC).toBeDefined();
expect(actionC?.command).toBe(`CRTBNDRPG NAME(&NAME) THEPARM('&RELATIVEPATH')`);
});
});