Skip to content

Commit 9267e59

Browse files
committed
Readded and modified compiler tests
Removed dependencies (dedent, fs-extra)
1 parent b864105 commit 9267e59

15 files changed

Lines changed: 120 additions & 57 deletions

package-lock.json

Lines changed: 0 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
"node": ">=8.5.0"
2222
},
2323
"dependencies": {
24-
"dedent": "^0.7.0",
25-
"fs-extra": "^5.0.0",
2624
"yargs": "^11.0.0"
2725
},
2826
"devDependencies": {
29-
"@types/fs-extra": "^5.0.1",
3027
"@types/node": "^9.4.7",
3128
"@types/yargs": "^11.0.0",
3229
"alsatian": "^2.2.1",

src/CommandLineParser.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import * as path from "path";
33
import * as ts from "typescript";
44
import * as yargs from "yargs";
55

6-
// ES6 syntax broken
7-
import dedent = require("dedent");
8-
96
export interface CompilerOptions extends ts.CompilerOptions {
107
addHeader?: boolean;
118
luaTarget?: string;

test/compiler/compiler.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Expect, Setup, Teardown, Test, TestCase } from "alsatian";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
import { execCommandLine } from "../../src/Compiler";
5+
6+
/**
7+
* Find all files inside a dir, recursively.
8+
*/
9+
function getAllFiles(dir: string): string[] {
10+
return fs.readdirSync(dir).reduce(
11+
(files, file) => {
12+
const name = path.join(dir, file);
13+
const isDirectory = fs.statSync(name).isDirectory();
14+
return isDirectory ? [...files, ...getAllFiles(name)] : [...files, name];
15+
},
16+
[]
17+
);
18+
}
19+
20+
export class CompilerTests {
21+
22+
private existingFiles: string[];
23+
private filesAfterCompile: string[];
24+
25+
@Setup
26+
public setup() {
27+
this.existingFiles = getAllFiles(path.resolve(__dirname, "./project"));
28+
this.filesAfterCompile = [];
29+
}
30+
31+
@TestCase("tsconfig.default.json",
32+
"typescript_lualib.lua",
33+
"test_src/test_lib/file.lua",
34+
"test_src/main.lua")
35+
@TestCase("tsconfig.outDir.json",
36+
"out_dir/typescript_lualib.lua",
37+
"out_dir/test_src/test_lib/file.lua",
38+
"out_dir/test_src/main.lua")
39+
@TestCase("tsconfig.rootDir.json",
40+
"test_src/typescript_lualib.lua",
41+
"test_src/test_lib/file.lua",
42+
"test_src/main.lua")
43+
@TestCase("tsconfig.bothDirOptions.json",
44+
"out_dir/typescript_lualib.lua",
45+
"out_dir/test_lib/file.lua",
46+
"out_dir/main.lua")
47+
@Test("Compile project")
48+
public compileProject(tsconfig: string, ...expectedFiles: string[]) {
49+
const tsconfigPath = path.resolve(__dirname, "project", tsconfig);
50+
51+
// Compile project
52+
execCommandLine(["-p", tsconfigPath]);
53+
54+
this.filesAfterCompile = getAllFiles(path.resolve(__dirname, "project"));
55+
expectedFiles = expectedFiles.map((relPath) => path.resolve(__dirname, "project", relPath));
56+
expectedFiles.push(...this.existingFiles);
57+
58+
for (const existingFile of this.filesAfterCompile) {
59+
Expect(expectedFiles).toContain(existingFile);
60+
}
61+
}
62+
63+
@Teardown
64+
public teardown() {
65+
// Remove files taht were created by the test
66+
const createdFiles = this.filesAfterCompile.filter((v) => this.existingFiles.indexOf(v) < 0);
67+
for (const file of createdFiles) {
68+
fs.unlinkSync(file);
69+
}
70+
this.existingFiles = [];
71+
this.filesAfterCompile = [];
72+
}
73+
74+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Generated by TypescriptToLua v0.1.1
2+
-- https://github.com/Perryvw/TypescriptToLua
3+
require("typescript_lualib")
4+
function main()
5+
local main = 10
6+
7+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function main() {
2+
const main = 10;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Generated by TypescriptToLua v0.1.1
2+
-- https://github.com/Perryvw/TypescriptToLua
3+
require("typescript_lualib")
4+
local test = true
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const test = true;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.default.json",
3+
"compilerOptions": {
4+
"outDir": "out_dir",
5+
"rootDir": "test_src"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"luaTarget": "JIT"
3+
}

0 commit comments

Comments
 (0)