<commit_before>/* main.c  -  Foundation bind test for lua library  -  MIT License  -  2013 <NAME> / Rampant Pixels
 * 
 * This library provides a fork of the LuaJIT library with custom modifications for projects
 * based on our foundation library.
 * 
 * The latest source code maintained by Rampant Pixels is always available at
 * https://github.com/rampantpixels/lua_lib
 * 
 * For more information about LuaJIT, see
 * http://luajit.org/
 *
 * The MIT License (MIT)
 * Copyright (c) 2013 Rampant Pixels AB
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <lua/lua.h>
#include <foundation/foundation.h>
#include <test/test.h>


application_t test_foundation_application( void )
{
	application_t app = {0};
	app.name = "Foundation tests";
	app.short_name = "test_lua_foundation";
	app.config_dir = "test_lua_foundation";
	app.flags = APPLICATION_UTILITY;
	return app;
}


int test_foundation_initialize( void )
{
	return 0;
}


void test_foundation_shutdown( void )
{
}


DECLARE_TEST( foundation, log )
{
	lua_t* env = lua_allocate();

	log_suppress( ERRORLEVEL_NONE );
	
	const char* testcode =
	"local foundation = require(\"foundation\")\n"
	"local log = foundation.log\n"
	"local error = foundation.error\n"
	"log.suppress( error.LEVEL_NONE )\n"
	"log.debug( \"Testing log debug output\" )\n"
	"log.info( \"Testing log info output\" )\n"
	"log.warn( \"Testing log warning output\" )\n"
	"log.enable_prefix( false )\n"
	"log.error( \"Testing log error output without prefix\" )\n"
	"log.stdout( false )\n"
	"log.debug( \"Invisible on stdout\" )\n"
	"log.stdout( true )\n"
	"log.enable_prefix( true )\n"
	"log.suppress( error.LEVEL_INFO )\n";
	
	EXPECT_EQ( lua_eval_string( env, testcode ), LUA_OK );

	EXPECT_EQ( error(), ERROR_SCRIPT );
	
	lua_deallocate( env );
	
	return 0;
}


DECLARE_TEST( foundation, environment )
{
	lua_t* env = lua_allocate();

	log_suppress( ERRORLEVEL_NONE );
	log_infof( "Running environment lua tests" );
	
	const char* testcode =
	"local foundation = require( \"foundation\" )\n"
	"local ffi = require( \"ffi\" )\n"
	"local log = foundation.log\n"
	"local error = foundation.error\n"
	"local env = foundation.environment\n"
	"log.suppress( error.LEVEL_DEBUG )\n"
	"log.enable_prefix( false )\n"
	"log.info( \"Executable name: \" .. ffi.string( env.executable_name() ) )\n"
	"local cmdline = \"\"\n"
	"local cmdline_tab = env.command_line()\n"
	"local i = 1\n"
	"while cmdline_tab[i] ~= nil do\n"
	"  cmdline = cmdline .. \" \" .. cmdline_tab[i]\n"
	"  i = i + 1\n"
	"end\n"
	"log.info( \"Command line:\" .. cmdline )\n"
	"log.enable_prefix( true )\n"
	"log.suppress( error.LEVEL_INFO )\n";

	EXPECT_EQ( lua_eval_string( env, testcode ), LUA_OK );

	log_suppress( ERRORLEVEL_NONE );
	log_infof( "Done running environment lua tests" );<commit_msg>add checks that environment was allocated<commit_after>/* main.c  -  Foundation bind test for lua library  -  MIT License  -  2013 <NAME> / Rampant Pixels
 * 
 * This library provides a fork of the LuaJIT library with custom modifications for projects
 * based on our foundation library.
 * 
 * The latest source code maintained by Rampant Pixels is always available at
 * https://github.com/rampantpixels/lua_lib
 * 
 * For more information about LuaJIT, see
 * http://luajit.org/
 *
 * The MIT License (MIT)
 * Copyright (c) 2013 Rampant Pixels AB
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <lua/lua.h>
#include <foundation/foundation.h>
#include <test/test.h>


application_t test_foundation_application( void )
{
	application_t app = {0};
	app.name = "Foundation tests";
	app.short_name = "test_lua_foundation";
	app.config_dir = "test_lua_foundation";
	app.flags = APPLICATION_UTILITY;
	return app;
}


int test_foundation_initialize( void )
{
	return 0;
}


void test_foundation_shutdown( void )
{
}


DECLARE_TEST( foundation, log )
{
	lua_t* env = lua_allocate();

	log_suppress( ERRORLEVEL_NONE );

	EXPECT_NE( env, 0 );

	const char* testcode =
	"local foundation = require(\"foundation\")\n"
	"local log = foundation.log\n"
	"local error = foundation.error\n"
	"log.suppress( error.LEVEL_NONE )\n"
	"log.debug( \"Testing log debug output\" )\n"
	"log.info( \"Testing log info output\" )\n"
	"log.warn( \"Testing log warning output\" )\n"
	"log.enable_prefix( false )\n"
	"log.error( \"Testing log error output without prefix\" )\n"
	"log.stdout( false )\n"
	"log.debug( \"Invisible on stdout\" )\n"
	"log.stdout( true )\n"
	"log.enable_prefix( true )\n"
	"log.suppress( error.LEVEL_INFO )\n";
	
	EXPECT_EQ( lua_eval_string( env, testcode ), LUA_OK );

	EXPECT_EQ( error(), ERROR_SCRIPT );
	
	lua_deallocate( env );
	
	return 0;
}


DECLARE_TEST( foundation, environment )
{
	lua_t* env = lua_allocate();

	log_suppress( ERRORLEVEL_NONE );
	log_infof( "Running environment lua tests" );

	EXPECT_NE( env, 0 );

	const char* testcode =
	"local foundation = require( \"foundation\" )\n"
	"local ffi = require( \"ffi\" )\n"
	"local log = foundation.log\n"
	"local error = foundation.error\n"
	"local env = foundation.environment\n"
	"log.suppress( error.LEVEL_DEBUG )\n"
	"log.enable_prefix( false )\n"
	"log.info( \"Executable name: \" .. ffi.string( env.executable_name() ) )\n"
	"local cmdline = \"\"\n"
	"local cmdline_tab = env.command_line()\n"
	"local i = 1\n"
	"while cmdline_tab[i] ~= nil do\n"
	"  cmdline = cmdline .. \" \" .. cmdline_tab[i]\n"
	"  i = i + 1\n"
	"end\n"
	"log.info( \"Command line:\" .. cmdline )\n"
	"log.enable_prefix( true )\n"
	"log.suppress( error.LEVEL_INFO )\n";

	EXPECT_EQ( lua_eval_string( env, testcode ), LUA_OK );

	log_suppress( ERRORLEVEL_NONE );
	log_infof( "Done running environment lua tests" );
{'fraction_non_alphanumeric': 0.12019730010384216, 'fraction_numerical': 0.0036344755970924196, 'mean_word_length': 3.996757457846952, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5359109', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2469, 'n_words': 867}