1 | import os |
2 | |
3 | const vexe = @VEXE |
4 | |
5 | const tfolder = os.join_path(os.vtmp_dir(), 'v', 'vbump') |
6 | |
7 | fn testsuite_begin() { |
8 | os.mkdir_all(tfolder) or {} |
9 | } |
10 | |
11 | fn testsuite_end() { |
12 | os.rmdir_all(tfolder) or {} |
13 | } |
14 | |
15 | struct BumpTestCase { |
16 | file_name string |
17 | contents string |
18 | line int |
19 | expected_patch string |
20 | expected_minor string |
21 | expected_major string |
22 | } |
23 | |
24 | const test_cases = [ |
25 | BumpTestCase{ |
26 | file_name: 'v.mod' |
27 | contents: "Module { |
28 | name: 'Sample' |
29 | description: 'Sample project' |
30 | version: '1.2.6' |
31 | license: 'MIT' |
32 | dependencies: [] |
33 | } |
34 | |
35 | " |
36 | line: 3 |
37 | expected_patch: " version: '1.2.7'" |
38 | expected_minor: " version: '1.3.0'" |
39 | expected_major: " version: '2.0.0'" |
40 | }, |
41 | BumpTestCase{ |
42 | file_name: 'random_versions.vv' |
43 | contents: " |
44 | 1.1.2 |
45 | 1.2.5 |
46 | 3.21.73 |
47 | version = '1.5.1' |
48 | |
49 | " |
50 | line: 4 |
51 | expected_patch: "version = '1.5.2'" |
52 | expected_minor: "version = '1.6.0'" |
53 | expected_major: "version = '2.0.0'" |
54 | }, |
55 | BumpTestCase{ |
56 | file_name: 'sample_tool.v' |
57 | contents: "// Module comment and copyright information |
58 | import os |
59 | import flag |
60 | |
61 | const ( |
62 | tool_name = os.file_name(os.executable()) |
63 | tool_version = '0.1.33' |
64 | ) |
65 | fn main() { |
66 | // stuff |
67 | } |
68 | " |
69 | line: 6 |
70 | expected_patch: " tool_version = '0.1.34'" |
71 | expected_minor: " tool_version = '0.2.0'" |
72 | expected_major: " tool_version = '1.0.0'" |
73 | }, |
74 | ] |
75 | |
76 | fn run_individual_test(case BumpTestCase) ! { |
77 | test_file := os.join_path_single(tfolder, case.file_name) |
78 | |
79 | os.rm(test_file) or {} |
80 | os.write_file(test_file, case.contents)! |
81 | |
82 | os.execute_or_exit('${os.quoted_path(vexe)} bump --patch ${os.quoted_path(test_file)}') |
83 | patch_lines := os.read_lines(test_file)! |
84 | assert patch_lines[case.line] == case.expected_patch |
85 | |
86 | os.execute_or_exit('${os.quoted_path(vexe)} bump --minor ${os.quoted_path(test_file)}') |
87 | minor_lines := os.read_lines(test_file)! |
88 | assert minor_lines[case.line] == case.expected_minor |
89 | |
90 | os.execute_or_exit('${os.quoted_path(vexe)} bump --major ${os.quoted_path(test_file)}') |
91 | major_lines := os.read_lines(test_file)! |
92 | assert major_lines[case.line] == case.expected_major |
93 | |
94 | os.rm(test_file)! |
95 | } |
96 | |
97 | fn test_all_bump_cases() { |
98 | for case in test_cases { |
99 | run_individual_test(case) or { panic(err) } |
100 | } |
101 | } |
102 | |
103 | struct SkipTestCase { |
104 | file_name string |
105 | contents string |
106 | skip string |
107 | line int |
108 | expected_patch string |
109 | expected_minor string |
110 | expected_major string |
111 | } |
112 | |
113 | const skip_test_cases = [ |
114 | SkipTestCase{ |
115 | file_name: 'CITATION.cff' |
116 | contents: 'abstract: A sample CLI tool made in V that prints geometric shapes to the screen. |
117 | authors: |
118 | - alias: hungrybluedev |
119 | family-names: Haldar |
120 | given-names: Subhomoy |
121 | cff-version: 1.2.0 |
122 | date-released: 2023-04-20 |
123 | license: MIT |
124 | message: Please cite this software using these information. |
125 | repository-code: https://github.com/hungrybluedev/geo |
126 | title: geo |
127 | url: https://github.com/hungrybluedev/geo |
128 | version: 0.2.4 |
129 | ' |
130 | line: 12 |
131 | skip: 'cff-version' |
132 | expected_patch: 'version: 0.2.5' |
133 | expected_minor: 'version: 0.3.0' |
134 | expected_major: 'version: 1.0.0' |
135 | }, |
136 | ] |
137 | |
138 | fn run_skip_test(case SkipTestCase) ! { |
139 | test_file := os.join_path_single(tfolder, case.file_name) |
140 | |
141 | os.rm(test_file) or {} |
142 | os.write_file(test_file, case.contents)! |
143 | |
144 | os.execute_or_exit('${os.quoted_path(vexe)} bump --patch --skip="${case.skip}" ${os.quoted_path(test_file)}') |
145 | patch_lines := os.read_lines(test_file)! |
146 | assert patch_lines[case.line] == case.expected_patch |
147 | |
148 | os.execute_or_exit('${os.quoted_path(vexe)} bump --minor --skip="${case.skip}" ${os.quoted_path(test_file)}') |
149 | minor_lines := os.read_lines(test_file)! |
150 | assert minor_lines[case.line] == case.expected_minor |
151 | |
152 | os.execute_or_exit('${os.quoted_path(vexe)} bump --major --skip="${case.skip}" ${os.quoted_path(test_file)}') |
153 | major_lines := os.read_lines(test_file)! |
154 | assert major_lines[case.line] == case.expected_major |
155 | |
156 | os.rm(test_file)! |
157 | } |
158 | |
159 | fn test_all_skip_bump_cases() ! { |
160 | for case in skip_test_cases { |
161 | run_skip_test(case) or { panic(err) } |
162 | } |
163 | } |