docker-compiler-nextjs/docs/Test-00.md

72 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

`app.js` 启动后API 的测试地址为:
**`http://localhost:3000/run`**
---
### 测试方法
#### 使用 `curl` 测试
1. **测试 C 代码**
```bash
curl -X POST http://localhost:3000/run \
-H "Content-Type: application/json" \
-d '{
"code": "#include <stdio.h>\nint main() { printf(\"Hello, World!\\n\"); return 0; }",
"language": "c"
}'
```
2. **测试 Java 代码**
```bash
curl -X POST http://localhost:3000/run \
-H "Content-Type: application/json" \
-d '{
"code": "public class Main { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }",
"language": "java"
}'
```
#### 使用 Postman 测试
1. 打开 [Postman](https://www.postman.com/)。
2. 创建一个新的请求,选择 `POST` 方法。
3. 设置请求 URL 为 `http://localhost:3000/run`
4.`Headers` 中添加:
```
Key: Content-Type
Value: application/json
```
5.`Body` 中选择 `raw`,并输入测试数据,例如:
```json
{
"code": "#include <stdio.h>\nint main() { printf(\"Hello, World!\\n\"); return 0; }",
"language": "c"
}
```
6. 点击发送,查看返回结果。
---
### 返回结果示例
1. **成功输出**
```json
{
"output": "Hello, World!\n"
}
```
2. **编译错误**(例如 C 代码语法错误):
```json
{
"error": "main.c: In function 'main':\nmain.c:2:12: error: expected ';' before 'return'\n"
}
```
3. **运行时错误**(例如除零错误):
```json
{
"error": "Floating point exception (core dumped)"
}
```