source: frontend/node_modules/jake/test/integration/rule.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Jake JavaScript build tool
3 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17*/
18
19const PROJECT_DIR = process.env.PROJECT_DIR;
20const JAKE_CMD = `${PROJECT_DIR}/bin/cli.js`;
21
22let assert = require('assert');
23let exec = require('child_process').execSync;
24let fs = require('fs');
25let { Rule } = require(`${PROJECT_DIR}/lib/rule`);
26let { rmRf } = require(`${PROJECT_DIR}/lib/jake`);
27
28let cleanUpAndNext = function (callback) {
29 // Gotta add globbing to file utils rmRf
30 let tmpFiles = [
31 'tmp'
32 , 'tmp_ns'
33 , 'tmp_cr'
34 , 'tmp_p'
35 , 'tmp_pf'
36 , 'tmpbin'
37 , 'tmpsrc'
38 , 'tmp_dep1.c'
39 , 'tmp_dep1.o'
40 , 'tmp_dep1.oo'
41 , 'tmp_dep2.c'
42 , 'tmp_dep2.o'
43 , 'tmp_dep2.oo'
44 , 'foo'
45 , 'foo.html'
46 ];
47 tmpFiles.forEach(function (f) {
48 rmRf(f, {
49 silent: true
50 });
51 });
52 callback && callback();
53};
54
55suite('rule', function () {
56
57 this.timeout(7000);
58
59 setup(function (next) {
60 cleanUpAndNext(next);
61 });
62
63
64 // - name foo:bin/main.o
65 // - pattern bin/%.o
66 // - source src/%.c
67 //
68 // return {
69 // 'dep' : 'foo:src/main.c',
70 // 'file': 'src/main.c'
71 // };
72 test('Rule.getSource', function () {
73 let src = Rule.getSource('foo:bin/main.o', 'bin/%.o', 'src/%.c');
74 assert.equal('foo:src/main.c', src);
75 });
76
77 test('rule w/o pattern', function () {
78 let out = exec( `${JAKE_CMD} -q tmp`).toString().trim();
79 let output = [
80 "tmp_dep2.c task"
81 , "tmp_dep1.c task"
82 , "cp tmp_dep1.c tmp_dep1.o task"
83 , "cp tmp_dep2.c tmp_dep2.o task"
84 , "tmp task"];
85 assert.equal( output.join('\n'), out);
86 let data = fs.readFileSync(process.cwd() + '/tmp');
87 assert.equal('src_1src_2', data.toString());
88 cleanUpAndNext();
89 });
90
91 test('rule w pattern w/o folder w/o namespace', function () {
92 let out = exec( `${JAKE_CMD} -q tmp_p`).toString().trim();
93 let output = [
94 "tmp_dep2.c task"
95 , "tmp_dep1.c task"
96 , "cp tmp_dep1.c tmp_dep1.oo task"
97 , "cp tmp_dep2.c tmp_dep2.oo task"
98 , "tmp pattern task"];
99 let data;
100 assert.equal( output.join('\n'), out);
101 data = fs.readFileSync(process.cwd() + '/tmp_p');
102 assert.equal('src_1src_2 pattern', data.toString());
103 cleanUpAndNext();
104 });
105
106 test('rule w pattern w folder w/o namespace', function () {
107 let out = exec( `${JAKE_CMD} -q tmp_pf`).toString().trim();
108 let output = [
109 "tmpsrc/tmp_dep1.c task"
110 , "cp tmpsrc/tmp_dep1.c tmpbin/tmp_dep1.oo task"
111 , "tmpsrc/tmp_dep2.c task"
112 , "cp tmpsrc/tmp_dep2.c tmpbin/tmp_dep2.oo task"
113 , "tmp pattern folder task"];
114 let data;
115 assert.equal( output.join('\n'), out);
116 data = fs.readFileSync(process.cwd() + '/tmp_pf');
117 assert.equal('src/src_1src/src_2 pattern folder', data.toString());
118 cleanUpAndNext();
119 });
120
121 test.skip('rule w pattern w folder w namespace', function () {
122 let out = exec( `${JAKE_CMD} -q tmp_ns`).toString().trim();
123 let output = [
124 "tmpsrc/file2.c init task" // yes
125 , "tmpsrc/tmp_dep2.c task" // no
126 , "cp tmpsrc/tmp_dep2.c tmpbin/tmp_dep2.oo task" // no
127 , "tmpsrc/dep1.c task" // no
128 , "cp tmpsrc/dep1.c tmpbin/dep1.oo ns task" // no
129 , "cp tmpsrc/file2.c tmpbin/file2.oo ns task" // yes
130 , "tmp pattern folder namespace task"]; // yes
131 let data;
132 assert.equal( output.join('\n'), out);
133 data = fs.readFileSync(process.cwd() + '/tmp_ns');
134 assert.equal('src/src_1src/src_2src/src_3 pattern folder namespace', data.toString());
135 cleanUpAndNext();
136 });
137
138 test.skip('rule w chain w pattern w folder w namespace', function () {
139 let out = exec( `${JAKE_CMD} -q tmp_cr`).toString().trim();
140 let output = [
141 "chainrule init task"
142 , "cp tmpsrc/file1.tex tmpbin/file1.dvi tex->dvi task"
143 , "cp tmpbin/file1.dvi tmpbin/file1.pdf dvi->pdf task"
144 , "cp tmpsrc/file2.tex tmpbin/file2.dvi tex->dvi task"
145 , "cp tmpbin/file2.dvi tmpbin/file2.pdf dvi->pdf task"
146 , "tmp chainrule namespace task"];
147 let data;
148 assert.equal( output.join('\n'), out);
149 data = fs.readFileSync(process.cwd() + '/tmp_cr');
150 assert.equal('tex1 tex2 chainrule namespace', data.toString());
151 cleanUpAndNext();
152 });
153
154
155 ['precedence', 'regexPattern', 'sourceFunction'].forEach(function (key) {
156
157 test('rule with source file not created yet (' + key + ')', function () {
158 let write = process.stderr.write;
159 process.stderr.write = () => {};
160 rmRf('foo.txt', {silent: true});
161 rmRf('foo.html', {silent: true});
162 try {
163 exec(`${JAKE_CMD} ` + key + ':test');
164 }
165 catch(err) {
166 // foo.txt prereq doesn't exist yet
167 assert.ok(err.message.indexOf('Unknown task "foo.html"') > -1);
168 }
169 process.stderr.write = write;
170 });
171
172 test('rule with source file now created (' + key + ')', function () {
173 fs.writeFileSync('foo.txt', '');
174 let out = exec(`${JAKE_CMD} -q ` + key + ':test').toString().trim();
175 // Should run prereq and test task
176 let output = [
177 'created html'
178 , 'ran test'
179 ];
180 assert.equal(output.join('\n'), out);
181 });
182
183 test('rule with source file modified (' + key + ')', function (next) {
184 setTimeout(function () {
185 fs.writeFileSync('foo.txt', '');
186 let out = exec(`${JAKE_CMD} -q ` + key + ':test').toString().trim();
187 // Should again run both prereq and test task
188 let output = [
189 'created html'
190 , 'ran test'
191 ];
192 assert.equal(output.join('\n'), out);
193 //next();
194 cleanUpAndNext(next);
195 }, 1000); // Wait to do the touch to ensure mod-time is different
196 });
197
198 test('rule with existing objective file and no source ' +
199 ' (should be normal file-task) (' + key + ')', function () {
200 // Remove just the source file
201 fs.writeFileSync('foo.html', '');
202 rmRf('foo.txt', {silent: true});
203 let out = exec(`${JAKE_CMD} -q ` + key + ':test').toString().trim();
204 // Should treat existing objective file as plain file-task,
205 // and just run test-task
206 let output = [
207 'ran test'
208 ];
209 assert.equal(output.join('\n'), out);
210 cleanUpAndNext();
211 });
212
213 });
214
215});
216
217
Note: See TracBrowser for help on using the repository browser.