Skip to content

Commit

Permalink
moved from munit+mcover to utest+instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHaxe committed Nov 29, 2024
1 parent 383c537 commit 91ef4de
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 309 deletions.
15 changes: 1 addition & 14 deletions .github/workflows/checkstyle-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,9 @@ jobs:
- name: Build JSON schema
run: npx haxe buildSchema.hxml
- name: Run eval tests
run: npx haxe -D codecov_json testAndResources.hxml
run: npx haxe testAndResources.hxml
- name: Run JVM tests
run: npx haxe testJava.hxml
- name: Format and upload codeclimate coverage
if: success() && matrix.haxe-version == 'nightly'
run: |
( \
cd src; \
../cc-test-reporter format-coverage -t lcov ../lcov.info; \
../cc-test-reporter upload-coverage; \
)
# - name: Checkstyle report annotations
# if: success()
# uses: jwgmeligmeyling/checkstyle-github-action@master
# with:
# path: '**/check-style-report.xml'
- name: Upload results to codecov
if: success() && (matrix.haxe-version == 'nightly')
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
2 changes: 1 addition & 1 deletion .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "4.3.4",
"version": "4.3.6",
"resolveLibs": "scoped"
}
13 changes: 13 additions & 0 deletions build/commonCoverage.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-lib instrument

-D coverage-console-summary-reporter
-D coverage-console-file-summary-reporter
-D coverage-console-package-summary-reporter
-D coverage-lcov-reporter
-D coverage-codecov-reporter

-lib instrument
--macro instrument.Instrumentation.coverage(['checkstyle'], ['src'], [])
# --macro instrument.Instrumentation.coverage(['checkstyle'], ['src'], ['checkstyle.reporter', 'checkstyle.Main'])

#--macro mcover.MCover.coverage(['checkstyle'], ['src'], ['checkstyle.reporter', 'checkstyle.Main'])
10 changes: 7 additions & 3 deletions build/commonTest.hxml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
build/common.hxml
-cp test
-lib mcover
-lib munit
-lib utest
-lib test-adapter
-D unittest
-D UTEST_PRINT_TESTS
# -D UTEST_FAILURE_THROW

# -debug
--macro mcover.MCover.coverage(['checkstyle'], ['src'], ['checkstyle.reporter', 'checkstyle.Main'])

--macro CompileTime.importPackage("checkstyle.checks")
--macro CompileTime.importPackage("misc")
4 changes: 2 additions & 2 deletions haxe_libraries/haxeparser.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2" into haxeparser/4.3.0-rc.1/github/a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#49db59c303242c7e6ef1293e35ac5983f31f654d" into haxeparser/4.3.0-rc.1/github/49db59c303242c7e6ef1293e35ac5983f31f654d
-lib hxparse
-cp ${HAXE_LIBCACHE}/haxeparser/4.3.0-rc.1/github/a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2/src
-cp ${HAXE_LIBCACHE}/haxeparser/4.3.0-rc.1/github/49db59c303242c7e6ef1293e35ac5983f31f654d/src
-D haxeparser=4.3.0-rc.1
12 changes: 6 additions & 6 deletions haxe_libraries/hxnodejs.hxml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @install: lix --silent download "haxelib:/hxnodejs#12.1.0" into hxnodejs/12.1.0/haxelib
-cp ${HAXE_LIBCACHE}/hxnodejs/12.1.0/haxelib/src
# @install: lix --silent download "haxelib:/hxnodejs#12.2.0" into hxnodejs/12.2.0/haxelib
-cp ${HAXE_LIBCACHE}/hxnodejs/12.2.0/haxelib/src
-D hxnodejs=12.1.0
--macro allowPackage('sys')
# should behave like other target defines and not be defined in macro context
--macro define('nodejs')
--macro _internal.SuppressDeprecated.run()
--macro allowPackage('sys')
# should behave like other target defines and not be defined in macro context
--macro define('nodejs')
--macro _internal.SuppressDeprecated.run()
4 changes: 4 additions & 0 deletions haxe_libraries/instrument.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/instrument#1.2.0" into instrument/1.2.0/haxelib
-lib safety
-cp ${HAXE_LIBCACHE}/instrument/1.2.0/haxelib/src
-D instrument=1.2.0
3 changes: 3 additions & 0 deletions haxe_libraries/safety.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/safety#1.1.2" into safety/1.1.2/haxelib
-cp ${HAXE_LIBCACHE}/safety/1.1.2/haxelib/src
-D safety=1.1.2
4 changes: 4 additions & 0 deletions haxe_libraries/utest.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @install: lix --silent download "gh://github.com/haxe-utest/utest#f759c0aa257aa723b3dd607cf7cb53d16194d13f" into utest/2.0.0-alpha/github/f759c0aa257aa723b3dd607cf7cb53d16194d13f
-cp ${HAXE_LIBCACHE}/utest/2.0.0-alpha/github/f759c0aa257aa723b3dd607cf7cb53d16194d13f/src
-D utest=2.0.0-alpha
--macro utest.utils.Macro.importEnvSettings()
2 changes: 1 addition & 1 deletion src/checkstyle/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Main {
TEXT_PATH = path;
},
@doc("Set reporter style (XSLT)")
["-x", "--xslt"] => function(style:String) STYLE = style,
["-x", "--xslt"] => function(style:String) STYLE = style,
@doc("verbose logging")
["-v", "--verbose"] => function() checker.verbose = true,
@doc("Sets the number of checker threads")
Expand Down
65 changes: 34 additions & 31 deletions test/TestMain.hx
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
import massive.munit.TestRunner;
import mcover.coverage.MCoverage;
import mcover.coverage.munit.client.MCoverPrintClient;
#if (neko || cpp || hl)
import haxe.EntryPoint;
#end
#if codecov_json
import mcover.coverage.client.CodecovJsonPrintClient;
#else
import mcover.coverage.client.LcovPrintClient;
#end
import checkstyle.checks.CheckTestCase;
import checkstyle.config.ConfigParserTest;
import checkstyle.config.ExcludeManagerTest;
import checkstyle.detect.DetectCodingStyleTest;
import misc.CheckerTest;
import misc.ThreadTest;
import sys.io.File;
import utest.Runner;
import utest.ui.text.DiagnosticsReport;

class TestMain {
public function new() {
var suites:Array<Class<massive.munit.TestSuite>> = [TestSuite];
var runner:Runner = new Runner();

var client:MCoverPrintClient = new MCoverPrintClient();
#if codecov_json
MCoverage.getLogger().addClient(new CodecovJsonPrintClient());
#else
MCoverage.getLogger().addClient(new LcovPrintClient("Checkstyle Unittests"));
#end
var runner:TestRunner = new TestRunner(client);
runner.completionHandler = completionHandler;
#if (neko || cpp || hl)
EntryPoint.addThread(function() {
while (true) Sys.sleep(1.0);
var failed = false;
runner.onProgress.add(r -> {
if (!r.result.allOk()) {
failed = true;
}
});
#end
runner.run(suites);
runner.onComplete.add(_ -> {
completionHandler(!failed);
});

new DiagnosticsReport(runner);

var testClasses = CompileTime.getAllClasses(CheckTestCase);
for (test in testClasses) {
runner.addCase(Type.createInstance(test, []));
}

runner.addCase(new CheckerTest());
runner.addCase(new ConfigParserTest());
runner.addCase(new DetectCodingStyleTest());
runner.addCase(new ThreadTest());

runner.run();
}

function completionHandler(success:Bool) {
#if eval
if (!success) {
Sys.exit(1);
}
#else
Sys.exit(success ? 0 : 1);
#if instrument
instrument.coverage.Coverage.endCoverage();
#end
}

Expand Down
24 changes: 0 additions & 24 deletions test/TestSuite.hx

This file was deleted.

20 changes: 12 additions & 8 deletions test/checkstyle/checks/CheckTestCase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import byte.ByteData;
import checkstyle.CheckFile;
import checkstyle.Checker;
import checkstyle.Message;
import checkstyle.config.ExcludeManager;
import checkstyle.reporter.IReporter;
import checkstyle.reporter.ReporterManager;

class CheckTestCase<T:String> {
class CheckTestCase<T:String> implements ITest {
static inline var FILE_NAME:String = "Test.hx";

var checker:Checker;
var reporter:TestReporter;

public function new() {}

@Before
public function setup() {}
public function setup() {
ExcludeManager.INSTANCE.clear();
}

function assertMsg(check:Check, testCase:T, expected:String, ?defines:Array<Array<String>>, ?fileName:String, allowFailingAST:Bool = false,
?pos:PosInfos) {
function assertMsg(check:Check, testCase:T, expected:String, ?defines:Array<Array<String>>, ?fileName:String, allowFailingAST:Bool = false, ?pos:PosInfos) {
assertMessages(check, testCase, [expected], defines, fileName, allowFailingAST, pos);
}

Expand All @@ -40,12 +44,12 @@ class CheckTestCase<T:String> {
var messages:Array<Message> = checkMessages(testCase, check, defines, fileName, allowFailingAST, pos);
if ((expected.length == 1) && (expected.length != messages.length)) {
for (i in 0...messages.length) {
Assert.areEqual(expected[0], messages[i].message, pos);
Assert.equals(expected[0], messages[i]?.message, pos);
}
}
Assert.areEqual(expected.length, messages.length, pos);
Assert.equals(expected.length, messages.length, pos);
for (i in 0...expected.length) {
Assert.areEqual(expected[i], messages[i].message, pos);
Assert.equals(expected[i], messages[i]?.message, pos);
}
}

Expand All @@ -66,7 +70,7 @@ class CheckTestCase<T:String> {
}

@After
public function tearDown() {
public function teardown() {
checker = null;
reporter = null;
}
Expand Down
Loading

0 comments on commit 91ef4de

Please sign in to comment.