about summary refs log tree commit diff
path: root/pkgs/games/build-support/monogame-patcher/src/test.sh
blob: 9c51cd7e41f7ac06cdfa1eb8c7d63ac546ea5033 (plain) (blame)
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
set -x
cd "$(mktemp -d)"

cat > "a.cs" <<EOF
using System;

public class a {
    public static string replaceMe(string foo) {
        Console.WriteLine("foo called: " + foo);
        return "foo";
    }
}
EOF

cat > "b.cs" <<EOF
using System;
using System.IO;

public class b {
    public static string replacement(string bar) {
        if (bar == "nope")
            return "nope";
        Console.WriteLine("bar called: " + bar);
        return "bar";
    }

    public static void wrongFileStreamUse() {
        var fs = new FileStream("write_test.txt", FileMode.Open);
        if (fs.CanWrite)
            Console.WriteLine("can write");
        else
            Console.WriteLine("can not write");
    }
}
EOF

cat > "test1.cs" <<EOF
class test1 {
    public static void Main() {
        a.replaceMe("xxx");
        b.replacement("nope");
    }
}
EOF

cat > "test2.cs" <<EOF
class test1 {
    public static void Main() {
        b.wrongFileStreamUse();
    }
}
EOF

mcs a.cs -target:library -out:a.dll
mcs b.cs -target:library -out:b.dll

mcs test1.cs -r:a -r:b -out:test1.exe
mcs test2.cs -r:a -r:b -out:test2.exe

! "$out/bin/monogame-patcher" replace-call -i test1.exe \
    "System.String a::replaceMe(System.String)" \
    "System.String b::notfound(System.String)" \
    test1 2> /dev/null

"$out/bin/monogame-patcher" replace-call -i test1.exe \
    "System.String a::replaceMe(System.String)" \
    "System.String b::replacement(System.String)" \
    test1

test "$(mono test1.exe)" = "bar called: xxx"

echo foo > write_test.txt

test "$(mono test2.exe)" = "can write"

"$out/bin/monogame-patcher" fix-filestreams -i b.dll b

test "$(mono test2.exe)" = "can not write"

"$out/bin/monogame-patcher" --help 2>&1 | grep -q fix-filestreams