|
1 | 1 | local test = require("lde-test") |
2 | 2 | local git2 = require("git2-sys") |
3 | 3 |
|
4 | | -local tmpBase = os.tmpname() |
5 | | -os.remove(tmpBase) |
| 4 | +local sep = string.sub(package.config, 1, 1) |
| 5 | +local isWindows = sep == "\\" |
| 6 | + |
| 7 | +local tmpBase = (os.getenv("TEMP") or os.getenv("TMPDIR") or "/tmp") .. sep .. "git2-sys-test-" .. tostring(os.time()) |
6 | 8 |
|
7 | 9 | local function mkTmp(suffix) |
8 | 10 | local dir = tmpBase .. suffix |
9 | | - os.execute('mkdir -p "' .. dir .. '"') |
| 11 | + if isWindows then |
| 12 | + os.execute('mkdir "' .. dir .. '"') |
| 13 | + else |
| 14 | + os.execute('mkdir -p "' .. dir .. '"') |
| 15 | + end |
10 | 16 | return dir |
11 | 17 | end |
12 | 18 |
|
13 | 19 | local function mkCommit(dir, msg) |
| 20 | + local touch = isWindows and ('type nul > "' .. dir .. sep .. 'f"') or ('touch "' .. dir .. '/f"') |
14 | 21 | os.execute('git -C "' .. dir .. '" init') |
15 | 22 | os.execute('git -C "' .. dir .. '" config user.email "t@t.com"') |
16 | 23 | os.execute('git -C "' .. dir .. '" config user.name "T"') |
17 | | - os.execute('touch "' .. dir .. '/f"') |
| 24 | + os.execute(touch) |
18 | 25 | os.execute('git -C "' .. dir .. '" add f') |
19 | 26 | os.execute('git -C "' .. dir .. '" commit -m "' .. msg .. '"') |
20 | 27 | end |
|
47 | 54 |
|
48 | 55 | test.it("commitLookup returns correct metadata", function() |
49 | 56 | local dir = mkTmp("meta") |
50 | | - os.execute('git -C "' .. dir .. '" init || true') |
51 | | - os.execute('mkdir -p "' .. dir .. '"') |
52 | | - os.execute('git -C "' .. dir .. '" init') |
53 | | - os.execute('git -C "' .. dir .. '" config user.email "a@b.com"') |
54 | | - os.execute('git -C "' .. dir .. '" config user.name "Alice"') |
55 | | - os.execute('touch "' .. dir .. '/f"') |
56 | | - os.execute('git -C "' .. dir .. '" add f') |
57 | | - os.execute('git -C "' .. dir .. '" commit -m "hello world"') |
| 57 | + mkCommit(dir, "hello world") |
58 | 58 | local repo = git2.open(dir) |
59 | 59 | local sha = repo.head() |
60 | 60 | local c = repo.commitLookup(sha) |
61 | 61 | test.equal(c.id, sha) |
62 | 62 | test.truthy(c.summary:find("hello world")) |
63 | | - test.equal(c.author.name, "Alice") |
64 | | - test.equal(c.author.email, "a@b.com") |
| 63 | + test.equal(c.author.name, "T") |
| 64 | + test.equal(c.author.email, "t@t.com") |
65 | 65 | test.truthy(c.time > 0) |
66 | 66 | end) |
67 | 67 |
|
|
0 commit comments