-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hpp
32 lines (26 loc) · 1.09 KB
/
Test.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
#include "JmlCommandline.hpp"
namespace mc {
inline auto runTestScript(JmlCommandline const& cli) -> juce::Result
{
auto state = sol::state{};
state.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string);
lua::bindings::allJuceModules(state);
auto const scriptFile = juce::File{cli.scriptPath};
if (cli.verbose) { std::cout << "Run test: " << scriptFile.getFileNameWithoutExtension().toStdString() << '\n'; }
scriptFile.getParentDirectory().setAsCurrentWorkingDirectory();
auto script = state.load_file(scriptFile.getFullPathName().toStdString());
if (not script.valid()) {
sol::error const error = script;
return juce::Result::fail(error.what());
}
auto factory = script.get<sol::protected_function>();
auto result = factory();
if (not result.valid()) {
sol::error const error = result;
return juce::Result::fail(error.what());
}
if (cli.verbose) { std::cout << "Done test: " << scriptFile.getFileNameWithoutExtension().toStdString() << '\n'; }
return juce::Result::ok();
}
} // namespace mc