Skip to content

Commit

Permalink
Add tests for source-header on hlc
Browse files Browse the repository at this point in the history
  • Loading branch information
tobil4sk committed Sep 10, 2021
1 parent 90d30fe commit 3c87faf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/misc/hl/projects/Issue10376/CheckSourceHeader.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sys.FileSystem;

final FILE = "out/main.c";

function deleteDirectory(path:String) {
if (!FileSystem.isDirectory(path))
return FileSystem.deleteFile(path);

for (item in FileSystem.readDirectory(path))
deleteDirectory('$path/$item');

FileSystem.deleteDirectory(path);
}

function main() {
final args = Sys.args();

final code =
try {
switch args {
case [""]:
checkForEmptySourceHeader(FILE);
case [expected]:
checkSourceHeader(FILE, expected);
case _:
throw "Incorrect number of arguments to script.";
}
0;
} catch (e){
Sys.stderr().writeString(e + "\n");
1;
}

deleteDirectory("out");
Sys.exit(code);
}

function checkForEmptySourceHeader(path:String) {
final content = getCSourceContent(path);

if (StringTools.startsWith(content, "// "))
throw "File has a source header when none was expected: " + content.split("\n")[0];
}

function checkSourceHeader(path:String, expected:String) {
final content = getCSourceContent(path);

if (!StringTools.startsWith(content, "// " + expected))
throw "File source header does not start with expected: // " + expected +
"\nSource header: " + content.split("\n")[0];
}

function getCSourceContent(path:String) {
// have to skip the BOM character
return sys.io.File.getContent(path).substr(1);
}
5 changes: 5 additions & 0 deletions tests/misc/hl/projects/Issue10376/custom-header.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--main CheckSourceHeader
--hl out/main.c
-D no-compilation
-D source-header=custom
--cmd haxe --run CheckSourceHeader custom
5 changes: 5 additions & 0 deletions tests/misc/hl/projects/Issue10376/default-header.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--main CheckSourceHeader
--hl out/main.c
-D no-compilation

--cmd haxe --run CheckSourceHeader "Generated by HLC"
5 changes: 5 additions & 0 deletions tests/misc/hl/projects/Issue10376/no-header-dash.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--main CheckSourceHeader
--hl out/main.c
-D no-compilation
-D source-header=
--cmd haxe --run CheckSourceHeader ""

0 comments on commit 3c87faf

Please sign in to comment.