File: scenario.nut

package info (click to toggle)
simutrans 124.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,880 kB
  • sloc: cpp: 160,224; ansic: 9,382; sh: 1,237; awk: 1,081; makefile: 932; javascript: 2
file content (115 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// This file is part of the Simutrans project under the Artistic License.
// (see LICENSE.txt)
//


map.file = "empty-16x16.sve"

scenario.short_description = "Automated tests"
scenario.author = "ceeac"
scenario.version = "0.1"


//
// Includes
//

include("test_helpers")
include("all_tests")


//
// test runner stuff
//

local num_tests_done = 0
local num_tests = all_tests.len()
local error_msg = null


function run_all_tests()
{
	num_tests_done = 0
	error_msg = null

	print("============================================================")
	print("== Running tests ... =======================================")
	print("============================================================")

	foreach (i,test_func in all_tests) {
		local func_name = test_func.getinfos().name
		print("[" + (num_tests_done+1) + "/" + num_tests + "] " + func_name)
		test_func() // run the test
		++num_tests_done
	}

	print("Tests completed successfully.")
}


//
// Required for scenario
//

function get_rule_text(pl)
{
	return ttext("Don't touch.")
}


function get_goal_text(pl)
{
	return ttext("Wait for all tests to pass.")
}


function get_info_text(pl)
{
	if (error_msg != null) {
		// an error ocurred
		return error_msg
	}

	local msg = ttext("{ndone}/{ntests} completed.")
	msg.ndone = num_tests_done
	msg.ntests = num_tests
	return msg
}


function get_result_text(pl)
{
	return get_info_text(pl)
}


function is_tool_allowed(pl, tool_id, wt, name)
{
	return true
}


function start()
{
	run_all_tests()
}


function resume_game()
{
	run_all_tests()
}


function is_scenario_completed(pl)
{
	if (error_msg != null) {
		return -1
	}
	else if (num_tests == 0) {
		return 100
	}

	return (100*num_tests_done) / num_tests
}