-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile
116 lines (86 loc) · 1.99 KB
/
rakefile
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
require 'rake/clean'
CXX = 'g++'
SRC_FILES = Dir.glob('src/**').reject{ |f| f.end_with?('.hpp') || f == 'src/main.cpp' }.join(' ')
TEST_FILES = 'test/**.cpp'
CLEAN.include 'bin/**'
task :debug do
DEBUG_FLAGS = '-Wall -Wextra -static-libstdc++ -O0 -g'
OUT = '-o bin/debug'
system('rake clean')
system("#{CXX} #{DEBUG_FLAGS} #{SRC_FILES} src/main.cpp #{OUT}")
end
task :test do
TEST_FLAGS = '-Wall -Wextra -static-libstdc++ -O0 -g'
OUT = '-o bin/test'
system('rake clean')
system("#{CXX} #{TEST_FLAGS} #{SRC_FILES} #{TEST_FILES} #{OUT}")
system("./bin/test")
end
##
# HELP TASKS
#
# note: we use exit at the end to stop rake from treating arguments as other tasks
##
task :add_test do
file_name = ARGV[1]
raise('file already exists') if (File.exist?("test/#{file_name}"))
text = <<-TEXT
#include "../include/doctest.h"
#include "../src/#{file_name}.hpp"
TEST_CASE("") {
}
TEXT
File.open("test/#{file_name}_test.cpp", 'w') do |f|
f << text
end
exit
end
task :add_json_test do
file_name = ARGV[1]
text = <<-TEXT
TEST_CASE("load_from_json") {
auto text = R"(
{
"type": "Comp",
}
)";
auto comp_json = nlohmann::json::parse(text);
auto comp = Position::load_from_json(comp_json);
}
TEXT
File.open("test/#{file_name}_test.cpp", 'a') do |f|
f << text
end
exit
end
task :add_class do
file_name = ARGV[1]
raise('file already exists') if (File.exist?("src/#{file_name}.hpp"))
text = <<-TEXT
#pragma once
class #{file_name} {
public:
private:
};
TEXT
File.open("src/#{file_name}.hpp", 'w') do |f|
f << text
end
exit
end
task :add_component do
file_name = ARGV[1]
raise('file already exists') if (File.exist?("src/#{file_name}.hpp"))
text = <<-TEXT
#pragma once
#include "component.hpp"
class #{file_name} : Component<#{file_name}> {
public:
private:
};
TEXT
File.open("src/#{file_name}.hpp", 'w') do |f|
f << text
end
exit
end