forked from prajna-lang/prajna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler_tests.cpp
116 lines (97 loc) · 4.21 KB
/
compiler_tests.cpp
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
116
#include <filesystem>
#include <fstream>
#include "gtest/gtest.h"
#include "prajna/compiler/compiler.h"
#include "prajna/exception.hpp"
#include "tests/utility.hpp"
using namespace prajna;
struct PrintFileName {
template <class ParamType>
std::string operator()(const testing::TestParamInfo<ParamType>& info) const {
return std::filesystem::path(info.param).stem();
}
};
class CompilerSourceTests : public testing::TestWithParam<std::string> {};
TEST_P(CompilerSourceTests, TestSourceFromDirectory) {
auto compiler = Compiler::create();
std::string prajna_source_path = GetParam();
compiler->addPackageDirectoryPath(".");
compiler->compileBuiltinSourceFiles("prajna_builtin_packages");
compiler->compileProgram(prajna_source_path, false);
compiler->executateTestFunctions();
}
class CompilerScriptTests : public testing::TestWithParam<std::string> {};
TEST_P(CompilerScriptTests, TestScriptFromDirectory) {
auto compiler = Compiler::create();
compiler->compileBuiltinSourceFiles("prajna_builtin_packages");
std::string prajna_script_path = GetParam();
std::ifstream ifs(prajna_script_path);
while (ifs.good()) {
std::string code;
std::getline(ifs, code);
// 修复//注释的问题
code.append("\n");
compiler->executeCodeInRelp(code);
std::cout << std::endl;
}
}
// class CompilerErrorSourceTests : public testing::TestWithParam<std::string> {};
// TEST_P(CompilerErrorSourceTests, TestSourceFromDirectory) {
// auto compiler = Compiler::create();
// std::string prajna_source_path = GetParam();
// compiler->addPackageDirectoryPath(".");
// compiler->compileBuiltinSourceFiles("prajna_builtin_packages");
// EXPECT_THROW(compiler->compileProgram(prajna_source_path, false), prajna::CompileError);
// }
// class CompilerErrorScriptTests : public testing::TestWithParam<std::string> {};
// TEST_P(CompilerErrorScriptTests, TestScriptFromDirectory) {
// auto compiler = Compiler::create();
// compiler->addPackageDirectoryPath(".");
// compiler->compileBuiltinSourceFiles("prajna_builtin_packages");
// std::string prajna_script_path = GetParam();
// std::ifstream ifs(prajna_script_path);
// while (ifs.good()) {
// std::string code;
// std::getline(ifs, code);
// // 修复//注释的问题
// code.append("\n");
// compiler->executeCodeInRelp(code);
// std::cout << std::endl;
// }
// }
INSTANTIATE_TEST_SUITE_P(
CompilerScriptTestsInstance, CompilerScriptTests,
testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_scripts")), PrintFileName());
// 会遍历整个文件夹里的文件
INSTANTIATE_TEST_SUITE_P(
CompilerSourceTestsInstance, CompilerSourceTests,
testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_sources")), PrintFileName());
// INSTANTIATE_TEST_SUITE_P(
// CompilerErrorScriptTestsInstance, CompilerErrorScriptTests,
// testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_error_scripts")),
// PrintFileName());
// // 会遍历整个文件夹里的文件
// INSTANTIATE_TEST_SUITE_P(
// CompilerErrorSourceTestsInstance, CompilerErrorSourceTests,
// testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_error_sources")),
// PrintFileName());
#ifdef PRAJNA_WITH_GPU
INSTANTIATE_TEST_SUITE_P(
CompilerScriptTestsGpuInstance, CompilerScriptTests,
testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_gpu_scripts")),
PrintFileName());
// 会遍历整个文件夹里的文件
INSTANTIATE_TEST_SUITE_P(
CompilerSourceTestsGpuInstance, CompilerSourceTests,
testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_gpu_sources")),
PrintFileName());
// INSTANTIATE_TEST_SUITE_P(
// CompilerErrorScriptTestsGpuInstance, CompilerErrorScriptTests,
// testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_error_gpu_scripts")),
// PrintFileName());
// // 会遍历整个文件夹里的文件
// INSTANTIATE_TEST_SUITE_P(
// CompilerErrorSourceTestsGpuInstance, CompilerErrorSourceTests,
// testing::ValuesIn(prajna::tests::getFiles("tests/compiler/prajna_error_gpu_sources")),
// PrintFileName());
#endif