From 8716801c8c59459471d9a4ef6aaea3a03d4e0f6d Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 3 Mar 2021 22:00:01 +0000 Subject: [PATCH] Unit-test for Nasal parsing bug --- .../unit_tests/Scripting/testNasalSys.cxx | 35 +++++++++++++++++++ .../unit_tests/Scripting/testNasalSys.hxx | 2 ++ 2 files changed, 37 insertions(+) diff --git a/test_suite/unit_tests/Scripting/testNasalSys.cxx b/test_suite/unit_tests/Scripting/testNasalSys.cxx index 85d571ed4..ce694f026 100644 --- a/test_suite/unit_tests/Scripting/testNasalSys.cxx +++ b/test_suite/unit_tests/Scripting/testNasalSys.cxx @@ -168,3 +168,38 @@ void NasalSysTests::testAirportGhost() CPPUNIT_ASSERT(ok); } + +// https://sourceforge.net/p/flightgear/codetickets/2246/ + +void NasalSysTests::testCompileLarge() +{ + auto nasalSys = globals->get_subsystem(); + nasalSys->getAndClearErrorList(); + + + string code = "var foo = 0;\n"; + for (int i=0; i<14; ++i) { + code = code + code; + } + + nasalSys->parseAndRun(code); + +// bool ok = FGTestApi::executeNasal(R"( +//var try_compile = func(code) { +// call(compile, [code], nil,nil,var err=[]); +// return size(err); +//} +// +//var expression = "var foo = 0;\n"; +//var code = ""; +// +//for(var i=0;i<=10000;i+=1) { +// code ~= expression; +// if (try_compile(code) == 1) { +// print("Error compiling, LOC count is:", i+1); +// break; +// } +//} +// )"); +// CPPUNIT_ASSERT(ok); +} diff --git a/test_suite/unit_tests/Scripting/testNasalSys.hxx b/test_suite/unit_tests/Scripting/testNasalSys.hxx index 5a5544136..b328de3b3 100644 --- a/test_suite/unit_tests/Scripting/testNasalSys.hxx +++ b/test_suite/unit_tests/Scripting/testNasalSys.hxx @@ -34,6 +34,7 @@ class NasalSysTests : public CppUnit::TestFixture CPPUNIT_TEST(testStructEquality); CPPUNIT_TEST(testCommands); CPPUNIT_TEST(testAirportGhost); + CPPUNIT_TEST(testCompileLarge); CPPUNIT_TEST_SUITE_END(); public: @@ -47,6 +48,7 @@ public: void testStructEquality(); void testCommands(); void testAirportGhost(); + void testCompileLarge(); }; #endif // _FG_NASALSYS_UNIT_TESTS_HXX