Skip to content

Commit

Permalink
Don't rely on the order of environment variables in tests
Browse files Browse the repository at this point in the history
The order can depend on a number of factors; the test should not
define what the order of env variables should be in a specific runtime.
  • Loading branch information
loganek committed May 9, 2023
1 parent 1b1d4a5 commit 22b46a8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/assemblyscript/testsuite/environ_get-multiple-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ const dataBuf = memory.data(sizeof<usize>() * 2);
let err = environ_sizes_get(dataBuf, dataBuf + sizeof<usize>());
assert(err == errno.SUCCESS);

const expected = new Set<String>();
expected.add("a=text");
expected.add('b=escap " ing');
expected.add("c=new\nline");

const envCount = load<usize>(dataBuf);
assert(envCount == 3);
assert(envCount == expected.size);

const dataSize = load<usize>(dataBuf, sizeof<usize>());
const ptrsSize = envCount * sizeof<usize>();
Expand All @@ -20,11 +25,10 @@ const envBuf = __alloc(envBufSize);
err = environ_get(envBuf, envBuf + ptrsSize);
assert(err == errno.SUCCESS);

const expected = ["a=text", 'b=escap " ing', "c=new\nline"];

for (let i = 0; i < <i32>envCount; ++i) {
const ptr = load<usize>(envBuf + i * sizeof<usize>());
const str = String.UTF8.decodeUnsafe(ptr, ptr + envBufSize - envBuf, true);
assert(str == expected[i]);
assert(expected.has(str));
expected.delete(str);
}
__free(envBuf);

0 comments on commit 22b46a8

Please sign in to comment.