File: magicgen-test.sh

package info (click to toggle)
golang-github-checkpoint-restore-go-criu 7.2.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,796 kB
  • sloc: makefile: 231; ansic: 195; python: 137; sh: 110
file content (42 lines) | stat: -rwxr-xr-x 737 bytes parent folder | download
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
#!/bin/bash
# print all commands to stdout for debugging
set -x

# generate sample input file
cat > input.h <<EOF
#define TEST 0xbc614e
EOF

# generate expected output file
cat > expected.go <<EOF
// Code generated by magicgen. DO NOT EDIT.

package magic

type MagicMap struct {
	ByName  map[string]uint64
	ByValue map[uint64]string
}

func LoadMagic() MagicMap {
	magicMap := MagicMap{
		ByName:  make(map[string]uint64),
		ByValue: make(map[uint64]string),
	}
	magicMap.ByName["TEST"] = 12345678
	magicMap.ByValue[12345678] = "TEST"
	return magicMap
}
EOF

python3 magicgen.py input.h output.go
cmp output.go expected.go
if [[ $? -eq 0 ]]
then
	echo "---PASS---"
	exit 0
else
	echo "---FAIL---"
	diff output.go expected.go
	exit 1
fi