File: test_mod2c.in

package info (click to toggle)
nrn-mod2c 0.9%2Bgit220919-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,224 kB
  • sloc: cpp: 11,513; ansic: 11,466; yacc: 1,478; lex: 214; sh: 38; perl: 33; makefile: 2
file content (59 lines) | stat: -rwxr-xr-x 1,118 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

# usage: test_mod2c MOD2C MODFILE MODFILE_DIR CFILE

if [ $# -ne 4 ]; then
    echo 'usage: test_mod2c MOD2C MODFILE MODFILE_DIR CFILE' >&2
    exit 1
fi

mod2c="$1"
modinput="$2"
modinput_dir="$3"
cmpfile="$4"

# mod2c writes to the directory in which it finds
# the MOD file, so make a temporary directory for
# this purpose.

tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)

function cleanup {
    if [ -d "$tmpdir" ]; then
        rm -r "$tmpdir"
    fi
}

trap cleanup EXIT

function realpath {
    echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
}

cp "$modinput" "$tmpdir"
cp "$modinput_dir"/*.inc "$tmpdir"

modpfx=$(basename "$modinput" .mod)

# canonicalize output
@MOD2CFILTER@ < "$cmpfile" > "$tmpdir/_check"

mod2c="$(realpath "$mod2c")"
( cd "$tmpdir"; "$mod2c" "$modpfx" )

if [ ! -e "$tmpdir/$modpfx".cpp ]; then
    echo "no output file generated" >&2
    exit 2
fi

@MOD2CFILTER@ < "$tmpdir/$modpfx".cpp > "$tmpdir/_out"
ntok=$(wc -l < "$tmpdir/_out")
echo "comparing $ntok tokens:"
if diff "$tmpdir/_out" "$tmpdir/_check"; then
    echo "ok"
    exit 0
else
    echo "mismatch"
    exit 3
fi