Files
kichikuou d4121032db system.ExistFile() should return false if path ends with a backslash
The system.ExistsFile() system call returns 1 if a file or directory
exists, but returns 0 when the provided path ends with a directory
separator, regardless of whether a directory exists at that location.

This subtle difference in behavior caused problems in Pastel Chime 3.
2026-03-07 11:31:43 +09:00

103 lines
2.2 KiB
C
Executable File

// -*-mode: C; coding: sjis; -*-
const bool true = 1;
const bool false = 0;
int tests_failed;
int tests_passed;
int total_failed = 0;
int total_passed = 0;
void test_start(string name)
{
tests_failed = 0;
tests_passed = 0;
}
void test_end(string name)
{
system.Output(name + ": " + string(tests_failed) + " failed; " + string(tests_passed) + " passed\n");
total_failed += tests_failed;
total_passed += tests_passed;
}
void test_equal(string msg, int actual, int expected)
{
if (actual != expected) {
system.Output("FAIL: " + msg + " (expected " + string(expected) + "; got " + string(actual) + ")\n");
tests_failed++;
} else {
tests_passed++;
}
}
void test_float(string msg, float actual, float expected)
{
float d = actual - expected;
if (d > 0.001 || d < -0.001) {
system.Output("FAIL: " + msg + " (expected " + string(expected) + "; got " + string(actual) + ")\n");
tests_failed++;
} else {
tests_passed++;
}
}
void test_bool(string msg, bool actual, bool expected)
{
if (actual != expected) {
system.Output("FAIL: " + msg + " (expected " + (expected ? "true" : "false") + "; got " + (actual ? "true" : "false") + ")\n");
tests_failed++;
} else {
tests_passed++;
}
}
void test_string(string msg, string actual, string expected)
{
if (actual != expected) {
system.Output("FAIL: " + msg + " (expected \"" + expected + "\"; got \"" + actual + "\")\n");
tests_failed++;
} else {
tests_passed++;
}
}
int main(void)
{
test_start("language features");
test_lang();
test_end("language features");
test_start("arithmetic");
test_arithmetic();
test_end("arithmetic");
test_start("strings");
test_strings();
test_end("strings");
test_start("structs");
test_structs();
test_end("structs");
test_start("arrays");
test_arrays();
test_end("arrays");
test_start("system");
test_system();
test_end("system");
test_start("Math.dll");
test_math();
test_end("Math.dll");
if (total_failed > 0) {
system.Output(string(total_failed) + " tests failed.\n");
} else {
system.Output("All tests passed „¤|�æ|„¢\n");
}
system.Exit(total_failed > 0);
return 0;
}