Selftests are only emitted (for Itinero2.0) if the approriate flag is specified, fix https://github.com/anyways-open/routing-profiles-aspects/issues/15
This commit is contained in:
parent
e9e53ac8b6
commit
1eb4139174
2 changed files with 52 additions and 38 deletions
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AspectedRouting.IO.itinero1;
|
||||
|
@ -29,7 +28,7 @@ namespace AspectedRouting.IO.itinero2
|
|||
private readonly string _behaviourName;
|
||||
private readonly IEnumerable<BehaviourTestSuite> _behaviourTestSuite;
|
||||
private readonly Context _context;
|
||||
private readonly DateTime _lastChangeTime;
|
||||
private readonly bool _includeTests;
|
||||
private readonly LuaParameterPrinter _parameterPrinter;
|
||||
private readonly ProfileMetaData _profile;
|
||||
|
||||
|
@ -39,7 +38,7 @@ namespace AspectedRouting.IO.itinero2
|
|||
public LuaPrinter2(ProfileMetaData profile, string behaviourName,
|
||||
Context context,
|
||||
List<AspectTestSuite> aspectTests, IEnumerable<BehaviourTestSuite> behaviourTestSuite,
|
||||
DateTime lastChangeTime)
|
||||
bool includeTests = true)
|
||||
{
|
||||
_skeleton = new LuaSkeleton.LuaSkeleton(context, true);
|
||||
_profile = profile;
|
||||
|
@ -47,29 +46,59 @@ namespace AspectedRouting.IO.itinero2
|
|||
_context = context;
|
||||
_aspectTests = aspectTests;
|
||||
_behaviourTestSuite = behaviourTestSuite;
|
||||
_lastChangeTime = lastChangeTime;
|
||||
_includeTests = includeTests;
|
||||
_parameterPrinter = new LuaParameterPrinter(_profile, _skeleton);
|
||||
}
|
||||
|
||||
private string TestRunner()
|
||||
{
|
||||
return new List<string>
|
||||
{
|
||||
"if (itinero == nil) then",
|
||||
" itinero = {}",
|
||||
" itinero.log = print",
|
||||
"",
|
||||
" -- Itinero is not defined -> we are running from a lua interpreter -> the tests are intended",
|
||||
" runTests = true",
|
||||
"",
|
||||
"",
|
||||
"else",
|
||||
" print = itinero.log",
|
||||
"end",
|
||||
"",
|
||||
"test_all()",
|
||||
"if (not failed_tests and not failed_profile_tests and print ~= nil) then",
|
||||
$" print(\"Tests OK ({_profile.Name}.{_behaviourName})\")",
|
||||
"end"
|
||||
}.Lined();
|
||||
}
|
||||
|
||||
public string ToLua()
|
||||
{
|
||||
var profileDescr = _profile.Behaviours[_behaviourName]["description"].Evaluate(_context).ToString();
|
||||
var header =
|
||||
new List<string> {
|
||||
new List<string>
|
||||
{
|
||||
$"name = \"{_profile.Name}.{_behaviourName}\"",
|
||||
$"description = \"{profileDescr} ({_profile.Description})\"",
|
||||
"",
|
||||
"-- The hierarchy of types that this vehicle is; mostly used to check access restrictions",
|
||||
$"vehicle_types = "+_skeleton.ToLua(new Constant( _profile.VehicleTyps.Select(v => new Constant(v)).ToArray()))
|
||||
"vehicle_types = " +
|
||||
_skeleton.ToLua(new Constant(_profile.VehicleTyps.Select(v => new Constant(v)).ToArray()))
|
||||
};
|
||||
|
||||
var testPrinter = new LuaTestPrinter(_skeleton,
|
||||
new List<string> { "unitTestProfile2" });
|
||||
var tests = testPrinter.GenerateFullTestSuite(
|
||||
_behaviourTestSuite.ToList(),
|
||||
new List<AspectTestSuite>(),
|
||||
true);
|
||||
var all = new List<string> {
|
||||
var tests = "";
|
||||
if (_includeTests) {
|
||||
var testPrinter = new LuaTestPrinter(_skeleton,
|
||||
new List<string> { "unitTestProfile2" });
|
||||
tests = testPrinter.GenerateFullTestSuite(
|
||||
_behaviourTestSuite.ToList(),
|
||||
new List<AspectTestSuite>(),
|
||||
true) + "\n\n" + TestRunner();
|
||||
}
|
||||
|
||||
var all = new List<string>
|
||||
{
|
||||
header.Lined(),
|
||||
"",
|
||||
GenerateMainFunction(),
|
||||
|
@ -87,25 +116,7 @@ namespace AspectedRouting.IO.itinero2
|
|||
"",
|
||||
string.Join("\n\n", _skeleton.GenerateConstants()),
|
||||
"",
|
||||
tests,
|
||||
"",
|
||||
|
||||
"if (itinero == nil) then",
|
||||
" itinero = {}",
|
||||
" itinero.log = print",
|
||||
"",
|
||||
" -- Itinero is not defined -> we are running from a lua interpreter -> the tests are intended",
|
||||
" runTests = true",
|
||||
"",
|
||||
"",
|
||||
"else",
|
||||
" print = itinero.log",
|
||||
"end",
|
||||
"",
|
||||
"test_all()",
|
||||
"if (not failed_tests and not failed_profile_tests and print ~= nil) then",
|
||||
$" print(\"Tests OK ({_profile.Name}.{_behaviourName})\")",
|
||||
"end"
|
||||
tests
|
||||
};
|
||||
|
||||
return all.Lined();
|
||||
|
|
|
@ -258,7 +258,7 @@ namespace AspectedRouting
|
|||
|
||||
private static void WriteOutputFiles(Context context,
|
||||
List<(AspectMetadata aspect, AspectTestSuite tests)> aspects, string outputDir,
|
||||
List<(ProfileMetaData profile, List<BehaviourTestSuite> profileTests)> profiles, DateTime lastChange)
|
||||
List<(ProfileMetaData profile, List<BehaviourTestSuite> profileTests)> profiles, bool includeTests)
|
||||
{
|
||||
if (!Directory.Exists($"{outputDir}/profile-documentation/"))
|
||||
{
|
||||
|
@ -315,7 +315,7 @@ namespace AspectedRouting
|
|||
context,
|
||||
aspectTests,
|
||||
profileTests.Where(testsSuite => testsSuite.BehaviourName == behaviourName),
|
||||
lastChange
|
||||
includeTests
|
||||
).ToLua();
|
||||
|
||||
var itinero2ProfileFile = Path.Combine($"{outputDir}/itinero2/{profile.Name}.{behaviourName}.lua");
|
||||
|
@ -351,12 +351,15 @@ namespace AspectedRouting
|
|||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
return "Usage: <directory where all aspects and profiles can be found> <outputdirectory>";
|
||||
return "Usage: <directory where all aspects and profiles can be found> <outputdirectory> [--include-tests]\n" +
|
||||
"The flag '--include-tests' will append some self-tests in the lua files";
|
||||
}
|
||||
|
||||
var inputDir = args[0];
|
||||
var outputDir = args[1];
|
||||
|
||||
var includeTests = args.Contains("--include-tests");
|
||||
var runRepl = !args.Contains("--no-repl");
|
||||
|
||||
if (!Directory.Exists(outputDir))
|
||||
{
|
||||
Directory.CreateDirectory(outputDir);
|
||||
|
@ -429,11 +432,11 @@ namespace AspectedRouting
|
|||
|
||||
if (testsOk)
|
||||
{
|
||||
WriteOutputFiles(context, aspects, outputDir, profiles, lastChange);
|
||||
WriteOutputFiles(context, aspects, outputDir, profiles, includeTests);
|
||||
}
|
||||
|
||||
|
||||
if (!args.Contains("--no-repl"))
|
||||
if (runRepl)
|
||||
{
|
||||
Repl(context, profiles
|
||||
.Select(p => p.profile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue