Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions indra/alscript/tests/aldiskcache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ namespace

s.write("a/.luaurc", "{}");
s.write("a/b/c/.luaurc", "{}");
const std::vector<std::string>& up = cache.upwards(s.at("a/b/c"), ".luaurc", 1, 10.0);
// A copy: upwards() answers with what it keeps, which a later call
// for the same folder fills again.
const std::vector<std::string> up = cache.upwards(s.at("a/b/c"), ".luaurc", 1, 10.0);
{
INFO("nearest first, to the root");
REQUIRE(up.size() >= 2);
Expand All @@ -150,7 +152,9 @@ namespace
s.write("a/b/.luaurc", "{}");
UNSCOPED_INFO("kept a moment");
REQUIRE(cache.upwards(s.at("a/b/c"), ".luaurc", 1, 11.0).size() == up.size());
const std::vector<std::string>& later = cache.upwards(s.at("a/b/c"), ".luaurc", 1, 10.0 + ALDiskCache::FRESH_SECONDS + 1.0);
REQUIRE(later.size() > 1);
UNSCOPED_INFO("then found");
CHECK(cache.upwards(s.at("a/b/c"), ".luaurc", 1, 10.0 + ALDiskCache::FRESH_SECONDS + 1.0)[1] == s.at("a/b/.luaurc"));
CHECK(later[1] == s.at("a/b/.luaurc"));
}
}
7 changes: 6 additions & 1 deletion indra/alscript/tests/alincludesearch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ namespace tut
facts.noFolders = false;
facts.inWorld = [](const std::string& name) { return name == "lib.lsl"; };
ALIncludeSearch::explainMissing(problems, facts);
REQUIRE(problems.size() == size_t(3));
UNSCOPED_INFO("the silence said first");
CHECK(problems.front().key == std::string("PreprocObjectUnanswered"));
UNSCOPED_INFO("one in the world, not taken from");
Expand All @@ -435,6 +436,7 @@ namespace tut
facts.disk = true;
facts.noFolders = true;
ALIncludeSearch::explainMissing(problems, facts);
REQUIRE(problems.size() == size_t(2));
UNSCOPED_INFO("no folder of the scripter's: the disk not looked in");
CHECK(problems[0].key == std::string("PreprocModuleNotOnDisk"));
UNSCOPED_INFO("but one asked from a file on disk is not second-guessed");
Expand Down Expand Up @@ -992,6 +994,7 @@ namespace tut
ALIncludeSearch::explainMissing(problems, facts);
{
INFO("the disk not looked in");
REQUIRE(problems.size() == size_t(1));
CHECK(problems[0].key == "PreprocModuleNotOnDisk");
CHECK(problems[0].args == std::vector<std::string>{ "./nowhere" });
}
Expand Down Expand Up @@ -1059,8 +1062,10 @@ namespace tut
ALPreprocessor::Found::Yes);
}
}
const std::vector<ALRequireNavigation::Suggestion> in_lib = search.suggest(own.self, "./lib/", true, own, disk);
REQUIRE(in_lib.size() > 1);
UNSCOPED_INFO("each one's whole path");
CHECK(search.suggest(own.self, "./lib/", true, own, disk)[1].path == std::string("./lib/http"));
CHECK(in_lib[1].path == std::string("./lib/http"));

// An include's: the file's own folder, by its search, names whole --
// an include's own `.lslh` and `.lsli` as well as `.lsl`.
Expand Down
1 change: 1 addition & 0 deletions indra/alscript/tests/allslconsts_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ namespace
REQUIRE(r.consts.size() == size_t(3));
const auto declaredAt = [&](const std::string& word, size_t from) {
const size_t at = r.text.find(word, from);
REQUIRE(at != std::string::npos);
const S32 line = static_cast<S32>(std::count(r.text.begin(), r.text.begin() + at, '\n'));
const size_t start = r.text.rfind('\n', at);
const S32 column = static_cast<S32>(start == std::string::npos ? at : at - start - 1);
Expand Down
17 changes: 10 additions & 7 deletions indra/alscript/tests/allsleffects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include "linden_common.h"

#include "linden_common.h"

#include "../lsl/allsleffects.h"
#include "../lsl/allslservice.h"

Expand Down Expand Up @@ -184,6 +182,7 @@ namespace
const std::vector<LSLFunctionExpression*> bumps = p.calls("bump");
const std::vector<LSLFunctionExpression*> sames = p.calls("same");
REQUIRE(bumps.size() == size_t(11));
REQUIRE(sames.size() == size_t(2));
const auto first = [&](LSLFunctionExpression* call) { return effects.mayRunFirst(statementOf(call), call); };
UNSCOPED_INFO("0: the right operand runs first");
CHECK(first(bumps[0]));
Expand Down Expand Up @@ -228,14 +227,18 @@ namespace
" l = [bump(), same(2)];\n" // same changes nothing, and bump does
"} }\n");
REQUIRE(q.script != nullptr);
const ALLSLEffects quiet(q.script);
const auto firstQ = [&](LSLFunctionExpression* call) { return quiet.mayRunFirst(statementOf(call), call); };
const ALLSLEffects quiet(q.script);
const std::vector<LSLFunctionExpression*> quiet_bumps = q.calls("bump");
const std::vector<LSLFunctionExpression*> quiet_sames = q.calls("same");
REQUIRE(quiet_bumps.size() == size_t(2));
REQUIRE(quiet_sames.size() == size_t(2));
const auto firstQ = [&](LSLFunctionExpression* call) { return quiet.mayRunFirst(statementOf(call), call); };
UNSCOPED_INFO("a quiet call before a quiet one");
CHECK(firstQ(q.calls("same")[0]));
CHECK(firstQ(quiet_sames[0]));
UNSCOPED_INFO("a call that reads before one that writes");
CHECK_FALSE(firstQ(q.calls("bump")[0]));
CHECK_FALSE(firstQ(quiet_bumps[0]));
UNSCOPED_INFO("a call that writes before a quiet one");
CHECK_FALSE(firstQ(q.calls("same")[1]));
CHECK_FALSE(firstQ(quiet_sames[1]));
}
TEST_CASE_METHOD(allsleffects_data, "allsleffects: a function's changes past the script and globals it reads through calls", "[allsleffects]")
{
Expand Down
76 changes: 53 additions & 23 deletions indra/alscript/tests/allsloptimizer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,47 +1504,69 @@ namespace
{
INFO("llGetPos is not");
CHECK_FALSE(ALLSLTraits::pure("llGetPos"));
CHECK(ALLSLTraits::of("llGetPos")->mustUse);
const ALLSLTraits::Trait* get_pos = ALLSLTraits::of("llGetPos");
REQUIRE(get_pos);
CHECK(get_pos->mustUse);
}
// What SLua makes of each, from the same definitions.
{
INFO("llGetSubString takes its second and third from one in SLua's ll");
CHECK(ALLSLTraits::of("llGetSubString")->slua == ALLSLTraits::SluaIndexArgs);
CHECK(ALLSLTraits::of("llGetSubString")->sluaIndexArgs == 0x6);
const ALLSLTraits::Trait* sub_string = ALLSLTraits::of("llGetSubString");
REQUIRE(sub_string);
CHECK(sub_string->slua == ALLSLTraits::SluaIndexArgs);
CHECK(sub_string->sluaIndexArgs == 0x6);
}
const ALLSLTraits::Trait* find_list = ALLSLTraits::of("llListFindList");
REQUIRE(find_list);
UNSCOPED_INFO("llListFindList answers an index, and SLua deprecates it");
CHECK(ALLSLTraits::of("llListFindList")->slua == (ALLSLTraits::SluaIndexResult | ALLSLTraits::SluaDeprecated));
CHECK(find_list->slua == (ALLSLTraits::SluaIndexResult | ALLSLTraits::SluaDeprecated));
const ALLSLTraits::Trait* same_group = ALLSLTraits::of("llSameGroup");
REQUIRE(same_group);
UNSCOPED_INFO("llSameGroup answers a boolean");
CHECK(ALLSLTraits::of("llSameGroup")->slua == ALLSLTraits::SluaBool);
CHECK(same_group->slua == ALLSLTraits::SluaBool);
const ALLSLTraits::Trait* timer_event = ALLSLTraits::of("llSetTimerEvent");
REQUIRE(timer_event);
UNSCOPED_INFO("llSetTimerEvent is llcompat's alone");
CHECK(ALLSLTraits::of("llSetTimerEvent")->slua == ALLSLTraits::SluaRemoved);
CHECK(timer_event->slua == ALLSLTraits::SluaRemoved);
{
INFO("llSay is as it was");
CHECK(ALLSLTraits::of("llSay")->slua == 0);
REQUIRE_FALSE(ALLSLTraits::of("llSay")->sluaUse);
const ALLSLTraits::Trait* say = ALLSLTraits::of("llSay");
REQUIRE(say);
CHECK(say->slua == 0);
CHECK_FALSE(say->sluaUse);
}
{
INFO("llAbs has math.abs in its stead");
REQUIRE(ALLSLTraits::of("llAbs")->sluaUse);
CHECK(std::string(ALLSLTraits::of("llAbs")->sluaUse) == "math.abs");
const ALLSLTraits::Trait* ll_abs = ALLSLTraits::of("llAbs");
REQUIRE(ll_abs);
REQUIRE(ll_abs->sluaUse);
CHECK(std::string(ll_abs->sluaUse) == "math.abs");
}
// How long each sleeps, under LSO and under Mono.
{
INFO("llSetPos sleeps 0.2 s");
CHECK(ALLSLTraits::of("llSetPos")->sleep == 0.2f);
CHECK(ALLSLTraits::of("llSetPos")->monoSleep == 0.2f);
const ALLSLTraits::Trait* set_pos = ALLSLTraits::of("llSetPos");
REQUIRE(set_pos);
CHECK(set_pos->sleep == 0.2f);
CHECK(set_pos->monoSleep == 0.2f);
}
const ALLSLTraits::Trait* params_fast = ALLSLTraits::of("llSetLinkPrimitiveParamsFast");
REQUIRE(params_fast);
UNSCOPED_INFO("llSetLinkPrimitiveParamsFast does not");
CHECK(ALLSLTraits::of("llSetLinkPrimitiveParamsFast")->sleep == 0.0f);
CHECK(params_fast->sleep == 0.0f);
{
INFO("llTextBox sleeps under LSO alone");
CHECK(ALLSLTraits::of("llTextBox")->sleep == 1.0f);
CHECK(ALLSLTraits::of("llTextBox")->monoSleep == 0.0f);
const ALLSLTraits::Trait* text_box = ALLSLTraits::of("llTextBox");
REQUIRE(text_box);
CHECK(text_box->sleep == 1.0f);
CHECK(text_box->monoSleep == 0.0f);
}
{
INFO("llOpenFloater under Mono alone");
CHECK(ALLSLTraits::of("llOpenFloater")->sleep == 0.0f);
CHECK(ALLSLTraits::of("llOpenFloater")->monoSleep == 0.2f);
const ALLSLTraits::Trait* open_floater = ALLSLTraits::of("llOpenFloater");
REQUIRE(open_floater);
CHECK(open_floater->sleep == 0.0f);
CHECK(open_floater->monoSleep == 0.2f);
}
// What item of the object's an argument names, by its LSL name or SLua's.
using Item = ALLSLTraits::Item;
Expand Down Expand Up @@ -1999,11 +2021,11 @@ namespace
UNSCOPED_INFO("no error in what was written: " + p.message + "\n" + r.text);
REQUIRE(p.severity != ALScriptProblem::Severity::Error);
}
return r.text;
return r;
};
const auto has = [](const std::string& text, const std::string& what) { return text.find(what) != std::string::npos; };

const std::string lso = run(ALLSLOptimizer::Target::LSO);
const std::string lso = run(ALLSLOptimizer::Target::LSO).text;
UNSCOPED_INFO("x != -1 as ~x, in a condition: " + lso);
CHECK(has(lso, "if (~a)"));
UNSCOPED_INFO("finds, both ways round, inside &&: " + lso);
Expand Down Expand Up @@ -2041,7 +2063,8 @@ namespace
UNSCOPED_INFO("elements whose order would show stay together");
CHECK_FALSE(has(lso, "l + llFrand(1) + llFrand(2)"));

const std::string mono = run(ALLSLOptimizer::Target::Mono);
const ALLSLOptimizer::Result monoRun = run(ALLSLOptimizer::Target::Mono);
const std::string& mono = monoRun.text;
UNSCOPED_INFO("Mono: x != -1 as ~x: " + mono);
CHECK(has(mono, "if (~a)"));
// Mono's ldc.i4 is five bytes, -1 and 1 too.
Expand All @@ -2053,10 +2076,17 @@ namespace
CHECK(has(mono, "g = ~-b;"));
UNSCOPED_INFO("Mono: ++a");
CHECK(has(mono, "++a;"));
UNSCOPED_INFO("Mono: what it wrote weighs what it says");
REQUIRE(mono.find("l = l") != std::string::npos);
// Its list's shapes weighed against the helpers they bring in, and
// whichever was smaller kept, with its weight.
UNSCOPED_INFO("Mono: l still added to, in whichever shape was kept");
CHECK(has(mono, "l = l"));
{
INFO("Mono: what it wrote weighs what it says");
CHECK(monoRun.weight.compiled);
CHECK(monoRun.weight.total == ALScriptWeigh::mono(mono).total);
}

const std::string luau = run(ALLSLOptimizer::Target::Luau);
const std::string luau = run(ALLSLOptimizer::Target::Luau).text;
UNSCOPED_INFO("Luau: x != -1 stays, ~ a library call there: " + luau);
CHECK(has(luau, "if (a != -1)"));
UNSCOPED_INFO("Luau: x - 1 stays");
Expand Down
14 changes: 8 additions & 6 deletions indra/alscript/tests/allslservice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,10 @@ namespace
TEST_CASE_METHOD(allslservice_data, "allslservice: another region's builtins: new ones known after and none declared twice", "[allslservice]")
{
const std::string base = std::string(AL_LSL_DEFINITIONS_DIR) + "/builtins.txt";
std::string error;
UNSCOPED_INFO("the first region's: " + error);
REQUIRE(service.loadBuiltins(base, error));
std::string why;
const bool first = service.loadBuiltins(base, why);
UNSCOPED_INFO("the first region's: " + why);
REQUIRE(first);
const std::string script = "default\n{\n state_entry()\n {\n integer n = llBrandNewThing(1);\n llOwnerSay((string)n);\n }\n}\n";
bool unknown = false;
for (const ALScriptProblem& problem : service.check(script))
Expand All @@ -937,13 +938,13 @@ namespace
llofstream out(path, std::ios::out | std::ios::binary | std::ios::trunc);
out << text << "integer llBrandNewThing( integer Value )\n";
}
const bool loaded = service.loadBuiltins(path, error);
const bool newer = service.loadBuiltins(path, why);
// Tailslide's table is the process's and only ever added to: what
// the file declares stays for every case after this one.
ll_test::StateGuard::accept("Tailslide's builtins");
LLFile::remove(path);
UNSCOPED_INFO("loaded: " + error);
CHECK(loaded);
UNSCOPED_INFO("loaded: " + why);
CHECK(newer);
unknown = false;
for (const ALScriptProblem& problem : service.check(script))
{
Expand Down Expand Up @@ -1070,6 +1071,7 @@ namespace
{
INFO("the outer call of two: " + said[2].message);
CHECK(said[2].line == 5);
REQUIRE_FALSE(said[2].args.empty());
CHECK(said[2].args[0] == "llGetListLength");
}
UNSCOPED_INFO("a NOLINT answers to the rule's name");
Expand Down
27 changes: 16 additions & 11 deletions indra/alscript/tests/allsltoslua_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ namespace
CHECK(has(r, "ll.Say(0, `{greet(detected[1]:getName())} {gCount}`)"));
{
INFO("state_entry last");
CHECK(r.text.find("-- state_entry") > r.text.find("LLEvents:on"));
const size_t entered = r.text.find("-- state_entry");
CHECK(entered != std::string::npos);
CHECK(entered > r.text.find("LLEvents:on"));
CHECK(has(r, "ll.Say(0, greet(\"world\"))"));
}
UNSCOPED_INFO("the note over its line");
Expand Down Expand Up @@ -415,7 +417,9 @@ namespace
{
INFO("a state not there said");
REQUIRE(looked != std::string::npos);
CHECK(looked < r.text.find("local leaving"));
const size_t leaving = r.text.find("local leaving");
CHECK(leaving != std::string::npos);
CHECK(looked < leaving);
}
require_checks_clean(r);
ALLSLToSLua::Options typed;
Expand Down Expand Up @@ -2415,14 +2419,12 @@ namespace
UNSCOPED_INFO("their SLua apart");
CHECK((shared[0]->sluaLast < shared[1]->sluaFirst || shared[1]->sluaLast < shared[0]->sluaFirst));
// The handler, over more than one LSL line, still holds both.
for (const ALLSLToSLua::Span& each : r.spans)
const auto handler = std::find_if(r.spans.begin(), r.spans.end(), [](const ALLSLToSLua::Span& each) { return each.lslFirst == 4; });
{
if (each.lslFirst == 4)
{
INFO("the handler over both");
REQUIRE(each.sluaFirst < shared[0]->sluaFirst);
REQUIRE(each.sluaLast >= shared[1]->sluaLast);
}
INFO("the handler over both");
REQUIRE(handler != r.spans.end());
CHECK(handler->sluaFirst < shared[0]->sluaFirst);
CHECK(handler->sluaLast >= shared[1]->sluaLast);
}
}

Expand Down Expand Up @@ -2559,8 +2561,11 @@ namespace
CAPTURE(entry.text);
{
INFO("state_entry's, kept");
CHECK(has(entry, "-- set up\n"));
CHECK(entry.text.find("-- set up") < entry.text.find("ll.OwnerSay"));
const size_t set_up = entry.text.find("-- set up\n");
const size_t said = entry.text.find("print(\"hi\")");
CHECK(set_up != std::string::npos);
CHECK(said != std::string::npos);
CHECK(set_up < said);
}
}

Expand Down
Loading
Loading