nspkg / tests / version_parity.v
31 lines · 28 sloc · 1.18 KB · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1// compare with version.c from the user's pacman checkout, without linking libalpm.
2module main
3
4import nspkg.tests.tooling
5import os
6
7fn main() {
8 run() or {
9 eprintln(err)
10 exit(1)
11 }
12}
13
14fn run() ! {
15 args := tooling.options(true)!
16 mut source := os.read_file(os.join_path(args.pacman, 'lib/libalpm/version.c'))!
17 include := '#include "util.h"'
18 if source.count(include) != 1 {
19 return error('version.c no longer has the expected util.h include')
20 }
21 source = source.replace(include, '#include <stdlib.h>\n#define SYMEXPORT\n#define alpm_pkg_vercmp reference_vercmp')
22 base := tooling.temporary('alpm-version-parity')!
23 defer { os.rmdir_all(base) or { eprintln(err) } }
24 implementation := os.join_path(base, 'reference.c')
25 header := os.join_path(base, 'reference.h')
26 os.write_file(implementation, source)!
27 os.write_file(header, 'int reference_vercmp(const char *, const char *);\n')!
28 program := os.join_path(base, 'parity.v')
29 os.write_file(program, os.read_file(os.join_path(@VMODROOT, 'tests', 'version_parity.v.in'))!.replace('@REFERENCE_C@', implementation).replace('@REFERENCE_H@', header))!
30 print(tooling.command(args.compiler, ['-path', '${@VMODROOT}|@vlib|@vmodules', 'run', program])!)
31}
32