Skip to content

Commit a1300c8

Browse files
Temporary change
1 parent dcae0b9 commit a1300c8

File tree

2 files changed

+63
-44
lines changed

2 files changed

+63
-44
lines changed

lib/view/actions.js

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import React from 'react';
44

5-
const Actions = ({prob,tests})=>{
5+
const Actions = ({prob,tests, runexamples})=>{
6+
7+
state = {
8+
prob: prob,
9+
tests: tests,
10+
runexamples: runexamples
11+
}
612

713
const change = (ele)=>{
814
ele.target.classList.toggle("icon-chevron-right")
@@ -16,44 +22,6 @@ const Actions = ({prob,tests})=>{
1622
// console.log(ele.target.nextElementSibling);
1723
}
1824

19-
const runexamples = ()=>{
20-
const path = require('path');
21-
var langcode = atom.config.get("codeblue.programmingLanguage")
22-
var ext = ""
23-
if(langcode==43) ext=".c"
24-
else if(langcode==54) ext=".cpp"
25-
else ext=".py"
26-
var wd = atom.config.get("codeblue.workingDirectory")
27-
var towhere = path.join(wd,prob.index)
28-
var torun = path.join(towhere,prob.index+ext)
29-
var inputfile = path.join(towhere,"examples/input1.in")
30-
31-
cmd = "python "+ torun +" < " + inputfile
32-
33-
const { exec } = require('child_process');
34-
exec(cmd,{
35-
timeout: 2500,
36-
maxBuffer: 1024*32,
37-
} ,function (error, stdout, stderr) {
38-
var res = {error: false, verdict: "none"}
39-
res.stdout = stdout
40-
if(error !== null){
41-
res.error = true
42-
if(error.killed){
43-
res.verdict = "TIME_LIMIT_EXCEEDED"
44-
}else if(error.code=="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"){
45-
res.verdict = "MEMORY_LIMIT_EXCEEDED"
46-
}else{
47-
res.verdict = "RUNTIME_ERROR"
48-
}
49-
res.stderr = stderr
50-
}
51-
console.log(res);
52-
})
53-
54-
55-
}
56-
5725
const togglesubmit = (ele)=>{
5826
var parent = ele.target.parentElement
5927
for (var i = 1; i < parent.children.length; i++) {
@@ -69,15 +37,15 @@ const Actions = ({prob,tests})=>{
6937

7038
return (
7139
<div className="actions">
72-
<h2 className="title titlename">{prob.index} - {prob.name}</h2>
40+
<h2 className="title titlename">{state.prob.index} - {state.prob.name}</h2>
7341
<div className="tasks">
7442
<div className="task">
7543
<div className="up">
7644
<span onClick={change} className="icon icon-chevron-right">Examples</span>
77-
<button className="actionbutton" onClick={runexamples}>Run all</button>
45+
<button className="actionbutton" onClick={state.runexamples}>Run all</button>
7846
</div>
7947
<div className="down">
80-
{tests && tests.map(test=>{
48+
{state.tests && state.tests.map(test=>{
8149
return <div className="verdict"> <span>example {test.n+1}</span> <i className={"icon-"+test.icon}></i> </div>
8250
})}
8351
</div>

lib/view/problems.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,53 @@ export default class Problems extends React.PureComponent {
3737
}
3838
}
3939

40+
runtest (i){
41+
const path = require('path');
42+
var prob = this.state.probs[this.state.curr]
43+
var langcode = atom.config.get("codeblue.programmingLanguage")
44+
var ext = ""
45+
if(langcode==43) ext=".c"
46+
else if(langcode==54) ext=".cpp"
47+
else ext=".py"
48+
var wd = atom.config.get("codeblue.workingDirectory")
49+
var towhere = path.join(wd,prob.index)
50+
var torun = path.join(towhere,prob.index+ext)
51+
var inputfile = path.join(towhere,"examples/input"+i+".in")
52+
53+
var allverdicts = this.state.allverdicts
54+
55+
cmd = "python "+ torun +" < " + inputfile
56+
57+
const { exec } = require('child_process');
58+
exec(cmd,{
59+
timeout: 2500,
60+
maxBuffer: 1024*32,
61+
} ,(error, stdout, stderr)=>{
62+
var res = {n: i-1, error: false, verdict: "none", icon: "check"}
63+
res.stdout = stdout
64+
if(error !== null){
65+
res.error = true
66+
if(error.killed){
67+
res.verdict = "TIME_LIMIT_EXCEEDED"
68+
res.icon = "clock"
69+
}else if(error.code=="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"){
70+
res.verdict = "MEMORY_LIMIT_EXCEEDED"
71+
res.icon = "database"
72+
}else{
73+
res.verdict = "RUNTIME_ERROR"
74+
res.icon = "alert"
75+
}
76+
res.stderr = stderr
77+
}
78+
allverdicts[prob.index][i-1] = res
79+
this.setState({allverdicts: allverdicts})
80+
})
81+
}
82+
83+
runexamples(){
84+
this.runtest(1)
85+
}
86+
4087
fetch(url){
4188
return new Promise((resolve, reject) => {
4289
request(url, (error, response, body) => {
@@ -100,7 +147,7 @@ export default class Problems extends React.PureComponent {
100147
outputs.push(io)
101148
}else{
102149
inputs.push(io)
103-
verdicts.push({n: Math.floor(i/2), verdict: "NONE", icon: "none"})
150+
verdicts.push({n: Math.floor(i/2), error:false, verdict: "none", icon: "none", stdout: "", stderr: "" })
104151
}
105152
}else{
106153
noftests[index] = Math.floor(i/2)
@@ -292,7 +339,11 @@ export default class Problems extends React.PureComponent {
292339
)
293340
}
294341
</div>
295-
{this.state.probs.length ? <Actions prob={this.state.probs[this.state.curr]} tests={this.state.allverdicts[this.state.probs[this.state.curr].index]}/> : null }
342+
{this.state.probs.length ? <Actions
343+
prob={this.state.probs[this.state.curr]}
344+
tests={this.state.allverdicts[this.state.probs[this.state.curr].index]}
345+
runexamples ={this.runexamples.bind(this)}
346+
/> : null }
296347
{this.state.probs.length ? <RecentSubmissions actions={this.state.actions}/> : null }
297348
</div>
298349
)}

0 commit comments

Comments
 (0)