Added test command.

This commit is contained in:
Sleepy Monax 2023-03-11 15:29:31 +01:00
parent 782065ec10
commit 0d4a17fb26
3 changed files with 33 additions and 2 deletions

View file

@ -1,7 +1,7 @@
import os
from typing import TextIO
from osdk.model import ComponentManifest, TargetManifest, Props
from osdk.model import Props
from osdk.ninja import Writer
from osdk.logger import Logger
from osdk.context import Context, contextFor
@ -122,7 +122,6 @@ class Paths:
def buildAll(targetSpec: str) -> Paths:
context = contextFor(targetSpec)
target = context.target
shell.mkdir(context.builddir())
ninjaPath = os.path.join(context.builddir(), "build.ninja")
@ -137,3 +136,23 @@ def buildAll(targetSpec: str) -> Paths:
os.path.join(context.builddir(), "lib"),
os.path.join(context.builddir(), "obj")
)
def testAll(targetSpec: str):
context = contextFor(targetSpec)
shell.mkdir(context.builddir())
ninjaPath = os.path.join(context.builddir(), "build.ninja")
with open(ninjaPath, "w") as f:
gen(f, context)
shell.exec(f"ninja", "-v", "-f", ninjaPath, "all")
for instance in context.enabledInstances():
if instance.isLib():
continue
if instance.id().endswith("-tests"):
print(f"Running {instance.id()}")
shell.exec(instance.outfile(context))

View file

@ -49,6 +49,15 @@ def runCmd(args: Args):
cmds += [Cmd("r", "run", "Run the target", runCmd)]
def testCmd(args: Args):
targetSpec = cast(str, args.consumeOpt(
"target", "host-" + shell.uname().machine))
builder.testAll(targetSpec)
cmds += [Cmd("t", "test", "Run all test targets", testCmd)]
def debugCmd(args: Args):
targetSpec = cast(str, args.consumeOpt(
"target", "host-" + shell.uname().machine))

View file

@ -36,6 +36,9 @@ class ComponentInstance:
self.sources = sources
self.resolved = resolved
def id(self) -> str:
return self.manifest.id
def isLib(self):
return self.manifest.type == Type.LIB