-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.mjs
54 lines (42 loc) · 1.22 KB
/
test.mjs
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
import { strictEqual } from 'node:assert'
import { it } from 'node:test'
import tio from './dist/index.js'
it('outputs "Hello, World!" in JavaScript', async () => {
const { output } = await tio("console.log('Hello, World!');")
strictEqual(output, 'Hello, World!\n')
})
it('outputs "Hello, World!" in Python 3', async () => {
const { output } = await tio("print('Hello, World!')", {
language: 'python3'
})
strictEqual(output, 'Hello, World!\n')
})
it('surpresses an infinite loop', async () => {
const { output, timedOut } = await tio('for (;;);', {
timeout: 2000
})
strictEqual(timedOut, true)
strictEqual(output, 'Request timed out after 2000ms')
})
it('works with custom compiler flags', async () => {
const code = `
fn main() {
#[cfg(feature = "something")]
println!("this will be printed");
}
`
const { output } = await tio(code, {
language: 'rust',
cflags: ['--cfg', 'feature="something"']
})
strictEqual(output, 'this will be printed\n')
})
it('works with custom command-line arguments', async () => {
const { output } = await tio(
'console.log(process.argv.slice(2).join(", "))',
{
argv: ['Hello', 'World!']
}
)
strictEqual(output, 'Hello, World!\n')
})