Skip to content

Commit

Permalink
added munit+instrument sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHaxe committed Jan 18, 2025
1 parent 9ae0232 commit 41b4bf5
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samples/munit-instrument/.haxerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "4.3.6",
"resolveLibs": "scoped"
}
11 changes: 11 additions & 0 deletions samples/munit-instrument/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "haxe-eval",
"request": "launch",
"args": ["test.hxml", "--lib", "test-adapter"]
}
]
}
15 changes: 15 additions & 0 deletions samples/munit-instrument/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"[haxe]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"haxeTestExplorer.coverageCommand": [
"${haxe}",
"testCoverage.hxml",
"-lib",
"test-adapter"
],
"haxeTestExplorer.lcovPath": "lcov.info",
"haxeTestExplorer.enableAttributableCoverage": true,
"haxeTestExplorer.enableCoverageUI": true,
}
13 changes: 13 additions & 0 deletions samples/munit-instrument/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "haxe",
"args": "active configuration",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
3 changes: 3 additions & 0 deletions samples/munit-instrument/haxe_libraries/hxjsonast.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/hxjsonast#1.1.0" into hxjsonast/1.1.0/haxelib
-cp ${HAXE_LIBCACHE}/hxjsonast/1.1.0/haxelib/src
-D hxjsonast=1.1.0
4 changes: 4 additions & 0 deletions samples/munit-instrument/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.3.1" into instrument/1.3.1/haxelib
-lib safety
-cp ${HAXE_LIBCACHE}/instrument/1.3.1/haxelib/src
-D instrument=1.3.1
4 changes: 4 additions & 0 deletions samples/munit-instrument/haxe_libraries/json2object.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/json2object#3.11.0" into json2object/3.11.0/haxelib
-lib hxjsonast
-cp ${HAXE_LIBCACHE}/json2object/3.11.0/haxelib/src
-D json2object=3.11.0
3 changes: 3 additions & 0 deletions samples/munit-instrument/haxe_libraries/mconsole.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/mconsole#1.6.0" into mconsole/1.6.0/haxelib
-cp ${HAXE_LIBCACHE}/mconsole/1.6.0/haxelib/
-D mconsole=1.6.0
5 changes: 5 additions & 0 deletions samples/munit-instrument/haxe_libraries/mcover.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @install: lix --silent download "haxelib:/mcover#2.2.2" into mcover/2.2.2/haxelib
-lib mconsole
-lib munit
-cp ${HAXE_LIBCACHE}/mcover/2.2.2/haxelib/
-D mcover=2.2.2
4 changes: 4 additions & 0 deletions samples/munit-instrument/haxe_libraries/mlib.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/mlib#2.0.3" into mlib/2.0.3/haxelib
# @run: haxelib run-dir mlib "${HAXE_LIBCACHE}/mlib/2.0.3/haxelib"
-cp ${HAXE_LIBCACHE}/mlib/2.0.3/haxelib/
-D mlib=2.0.3
6 changes: 6 additions & 0 deletions samples/munit-instrument/haxe_libraries/munit.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# @install: lix --silent download "haxelib:/munit#2.3.5" into munit/2.3.5/haxelib
# @run: haxelib run-dir munit "${HAXE_LIBCACHE}/munit/2.3.5/haxelib"
-lib mcover
-lib mlib
-cp ${HAXE_LIBCACHE}/munit/2.3.5/haxelib/
-D munit=2.3.5
3 changes: 3 additions & 0 deletions samples/munit-instrument/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
5 changes: 5 additions & 0 deletions samples/munit-instrument/haxe_libraries/test-adapter.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-lib json2object
-cp ../../test-adapter
-D test-adapter=2.0.7
${SCOPE_DIR}/../../test-adapter/extraParams.hxml
--macro Sys.println("haxe_libraries/test-adapter.hxml:3: [Warning] Using dev version of library test-adapter")
39 changes: 39 additions & 0 deletions samples/munit-instrument/src/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Main {
public function new() {
doNothing();
}

public function doSomething(condition:Bool) {
if (condition) {
doNothing();
return false;
} else {
doNothing();
}
doNothing();
return true;
}

public function doSomethingFullCoverage(condition:Bool) {
if (condition) {
doNothing();
return false;
} else {
doNothing();
}
doNothing();
return true;
}

public function doNothing() {
return true;
}

public function doMoreNothing() {
return true;
}

static function main() {
new Main();
}
}
4 changes: 4 additions & 0 deletions samples/munit-instrument/test.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-cp src
-cp tests
-lib munit
-x Test
10 changes: 10 additions & 0 deletions samples/munit-instrument/testCoverage.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-cp src
-cp tests
-lib munit
-lib instrument
-x Test

-D coverage-console-summary-reporter

--macro instrument.Instrumentation.coverage([''], ['src'], [])
-D instrument-quiet
46 changes: 46 additions & 0 deletions samples/munit-instrument/tests/Test.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import massive.munit.Assert;
import massive.munit.TestRunner;
import massive.munit.client.RichPrintClient;

class Test {
static function main() {
var client = new RichPrintClient();
var runner = new TestRunner(client);
runner.run([TestSuite]);

#if instrument
instrument.coverage.Coverage.endCoverage();
#end
}
}

class TestSuite extends massive.munit.TestSuite {
public function new() {
super();
add(TestMain);
}
}

class TestMain {
@Test
function testDoNothing() {
var main = new Main();

Assert.isTrue(main.doNothing());
}

@Test
function testDoSomething() {
var main = new Main();

Assert.isTrue(main.doSomething(false));
}

@Test
function testDoSomethingFullCoverage() {
var main = new Main();

Assert.isTrue(main.doSomethingFullCoverage(false));
Assert.isFalse(main.doSomethingFullCoverage(true));
}
}

0 comments on commit 41b4bf5

Please sign in to comment.