Skip to content

Commit 2f2cf05

Browse files
committed
*: EVERYTHING WORKS!
1 parent 9887f40 commit 2f2cf05

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

.github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Running ESLint
2323
run: npx eslint src/**/*.ts
2424
- name: Running Prettier
25-
run: npx prettier **/*.ts --write
25+
run: npx prettier src/**/*.ts typings.d.ts test.mjs --write
2626
- name: Commit
2727
uses: EndBug/add-and-commit@v9
2828
with:

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ Therefore, here are the full list of supported programming languages alongside w
776776
## Examples
777777

778778
<details>
779-
<summary><b>Evaluate a code</b></summary>
779+
<summary><b>Evaluating a code</b></summary>
780780

781781
```js
782782
const response = await tio('console.log("Hello, World!");')
@@ -796,7 +796,7 @@ console.log(response)
796796

797797
</details>
798798
<details>
799-
<summary><b>Evaluate a code from another programming language</b></summary>
799+
<summary><b>Evaluating a code from another programming language</b></summary>
800800

801801
```js
802802
let response = await tio('print("Hello, World!")', {
@@ -835,7 +835,7 @@ console.log(response)
835835

836836
</details>
837837
<details>
838-
<summary><b>Contain infinite loops with timeouts</b></summary>
838+
<summary><b>Surpressing infinite loops with timeouts</b></summary>
839839

840840
```js
841841
// make the response timeout after 10000 ms (10 seconds).
@@ -929,14 +929,14 @@ console.log(response)
929929
<summary><b>Passing in command-line arguments</b></summary>
930930

931931
```js
932-
let response = await tio('console.log(process.argv.slice(2))', {
933-
argv: ['hello', 'world']
932+
let response = await tio('console.log(process.argv.slice(2).join(", "))', {
933+
argv: ['Hello', 'World!']
934934
})
935935

936936
console.log(response)
937937
// =>
938938
// {
939-
// output: '["hello", "world"]\n',
939+
// output: 'Hello, World!\n',
940940
// timedOut: false,
941941
// realTime: 0.069,
942942
// userTime: 0.069,
@@ -946,14 +946,14 @@ console.log(response)
946946
// }
947947

948948
// tio.js uses [] (no command-line arguments) by default.
949-
tio.defaultArgv = ['hello', 'world']
949+
tio.defaultArgv = ['Hello', 'World!']
950950

951-
response = await tio('console.log(process.argv.slice(2))')
951+
response = await tio('console.log(process.argv.slice(2).join(", "))')
952952

953953
console.log(response)
954954
// =>
955955
// {
956-
// output: '["hello", "world"]\n',
956+
// output: 'Hello, World!\n',
957957
// timedOut: false,
958958
// realTime: 0.069,
959959
// userTime: 0.069,

src/index.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,15 @@ const tio: Tio = async (
132132
)
133133
} else if ('cflags' in options && !validStringArray(options.cflags)) {
134134
throw new TioError(
135-
`Compiler flags must be a valid array of strings. Got ${inspect(options.cflags)}`
135+
`Compiler flags must be a valid array of strings. Got ${inspect(
136+
options.cflags
137+
)}`
136138
)
137139
} else if ('argv' in options && !validStringArray(options.argv)) {
138140
throw new TioError(
139-
`Command-line arguments must be a valid array of strings. Got ${inspect(options.argv)}`
141+
`Command-line arguments must be a valid array of strings. Got ${inspect(
142+
options.argv
143+
)}`
140144
)
141145
}
142146

@@ -243,7 +247,9 @@ Object.defineProperty(tio, 'defaultCflags', {
243247
set(cflags: string[]) {
244248
if (!validStringArray(cflags)) {
245249
throw new TioError(
246-
`Compiler flags must be a valid array of strings. Got ${inspect(cflags)}`
250+
`Compiler flags must be a valid array of strings. Got ${inspect(
251+
cflags
252+
)}`
247253
)
248254
}
249255

@@ -262,7 +268,9 @@ Object.defineProperty(tio, 'defaultArgv', {
262268
set(argv: string[]) {
263269
if (!validStringArray(argv)) {
264270
throw new TioError(
265-
`Command-line arguments must be a valid array of strings. Got ${inspect(argv)}`
271+
`Command-line arguments must be a valid array of strings. Got ${inspect(
272+
argv
273+
)}`
266274
)
267275
}
268276

test.mjs

+32-5
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,52 @@ import { it } from 'node:test'
33

44
import tio from './dist/index.js'
55

6-
it('outputs Hello, World in JavaScript', async () => {
6+
it('outputs "Hello, World!" in JavaScript', async () => {
77
const { output } = await tio("console.log('Hello, World!');")
88

99
strictEqual(output, 'Hello, World!\n')
1010
})
1111

12-
it('outputs Hello, World in Python 3', async () => {
13-
tio.defaultLanguage = 'python3'
14-
const { output } = await tio("print('Hello, World!')")
12+
it('outputs "Hello, World!" in Python 3', async () => {
13+
const { output } = await tio("print('Hello, World!')", {
14+
language: 'python3'
15+
})
1516

1617
strictEqual(output, 'Hello, World!\n')
1718
})
1819

1920
it('surpresses an infinite loop', async () => {
2021
const { output, timedOut } = await tio('for (;;);', {
21-
language: 'javascript-node',
2222
timeout: 2000
2323
})
2424

2525
strictEqual(timedOut, true)
2626
strictEqual(output, 'Request timed out after 2000ms')
2727
})
28+
29+
it('works with custom compiler flags', async () => {
30+
const code = `
31+
fn main() {
32+
#[cfg(feature = "something")]
33+
println!("this will be printed");
34+
}
35+
`
36+
37+
const { output } = await tio(code, {
38+
language: 'rust',
39+
cflags: ['--cfg', 'feature="something"']
40+
})
41+
42+
strictEqual(output, 'this will be printed\n')
43+
})
44+
45+
it('works with custom command-line arguments', async () => {
46+
const { output } = await tio(
47+
'console.log(process.argv.slice(2).join(", "))',
48+
{
49+
argv: ['Hello', 'World!']
50+
}
51+
)
52+
53+
strictEqual(output, 'Hello, World!\n')
54+
})

0 commit comments

Comments
 (0)