Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit 19ae552

Browse files
committed
Add Mono support
1 parent f49acae commit 19ae552

File tree

4 files changed

+167
-3
lines changed

4 files changed

+167
-3
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- [C](https://en.wikipedia.org/wiki/C_(programming_language))/[C++](https://en.wikipedia.org/wiki/C%2B%2B)
2323
- [GCC (The **G**NU **C**ompiler **C**ollection)](https://gcc.gnu.org/)
2424
- [LLVM Clang](https://clang.llvm.org/)
25+
- [.NET](https://docs.microsoft.com/en-us/dotnet/) ([C#](https://docs.microsoft.com/en-us/dotnet/csharp/) & [Visual Basic](https://docs.microsoft.com/en-us/dotnet/visual-basic/))
26+
- [Mono](https://www.mono-project.com/)
2527
- [Go](https://golang.org/)
2628
- [`go`](https://golang.org/dl/)
2729
- [`gccgo` (GCC)](https://golang.org/doc/install/gccgo)
@@ -37,6 +39,7 @@
3739
- [Ruby](https://www.ruby-lang.org/en/)
3840
- [`ruby`](https://www.ruby-lang.org/en/downloads/)
3941

42+
4043
## Installation
4144
### From the [Python Package Index (PyPI)](https://pypi.org/)
4245
[dockerjudge · PyPI](https://pypi.org/project/dockerjudge/)
@@ -70,7 +73,7 @@ sudo make install # python3 setup.py install
7073
## Usage
7174
```python
7275
>>> from dockerjudge import judge
73-
>>> from dockerjudge.processor import GCC, Clang, Python, Node, OpenJDK
76+
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono
7477
>>>
7578
>>> judge(
7679
... GCC(GCC.Language.c), # or `GCC('c')` / `GCC('C')`, which means compile the source code in the C programming language with `gcc` command
@@ -305,6 +308,58 @@ sudo make install # python3 setup.py install
305308
],
306309
b'Syntax OK\n'
307310
]
311+
>>>
312+
>>> judge(
313+
... Mono(Mono.Language.csharp), # C# (Mono)
314+
... b'''
315+
... using System;
316+
...
317+
... public class HelloWorld
318+
... {
319+
... public static void Main(string[] args)
320+
... {
321+
... Console.WriteLine ("Hello Mono World");
322+
... }
323+
... }
324+
... ''',
325+
... [
326+
... (b'', b'Hello Mono World')
327+
... ]
328+
... )
329+
[
330+
[
331+
(<Status.AC: 'Accepted'>, (b'Hello Mono World\n', b''), 0.02)
332+
],
333+
b'Microsoft (R) Visual C# Compiler version 3.5.0-beta1-19606-04 (d2bd58c6)\n'
334+
b'Copyright (C) Microsoft Corporation. All rights reserved.\n'
335+
b'\n'
336+
]
337+
>>> judge(
338+
... Mono(Mono.Language.vb), # Visual Basic (Mono)
339+
... b'''
340+
... Imports System
341+
...
342+
... Module HelloWorld
343+
... Sub Main()
344+
... Console.WriteLine("Hello World!")
345+
... End Sub
346+
... End Module
347+
... ''',
348+
... [
349+
... (b'', b'Hello World!')
350+
... ]
351+
... )
352+
[
353+
[
354+
(<Status.AC: 'Accepted'>, (b'Hello World!\n', b''), 0.024)
355+
],
356+
b'Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.7 - tarball)\n'
357+
b'Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.\n'
358+
b'\n'
359+
b"Assembly 'mono, Version=0.0, Culture=neutral, PublicKeyToken=null' saved successfully to '/dockerjudge/0/mono.exe'.\r\n"
360+
b'Compilation successful\r\n'
361+
b'Compilation took 00:00:00.0000000\n'
362+
]
308363
```
309364

310365

README.zh_Hans_CN.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- [C](https://zh.wikipedia.org/zh-cn/C语言)/[C++](https://zh.wikipedia.org/zh-cn/C%2B%2B)
2323
- [GCC (The **G**NU **C**ompiler **C**ollection)](https://gcc.gnu.org/)
2424
- [LLVM Clang](https://clang.llvm.org/)
25+
- [.NET](https://docs.microsoft.com/zh-cn/dotnet/) ([C#](https://docs.microsoft.com/zh-cn/dotnet/csharp/) & [Visual Basic](https://docs.microsoft.com/zh-cn/dotnet/visual-basic/))
26+
- [Mono](https://www.mono-project.com/)
2527
- [Go](https://golang.google.cn/)
2628
- [`go`](https://golang.google.cn/dl/)
2729
- [`gccgo` (GCC)](https://golang.google.cn/doc/install/gccgo)
@@ -71,7 +73,7 @@ sudo make install # python3 setup.py install
7173
## 用法示例
7274
```python
7375
>>> from dockerjudge import judge
74-
>>> from dockerjudge.processor import GCC, Clang
76+
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono
7577
>>>
7678
>>> judge(
7779
... GCC(GCC.Language.c), # 或 `GCC('c')` / `GCC('C')`,意为用 `gcc` 命令编译 C 语言源码
@@ -306,6 +308,58 @@ sudo make install # python3 setup.py install
306308
],
307309
b'Syntax OK\n'
308310
]
311+
>>>
312+
>>> judge(
313+
... Mono(Mono.Language.csharp), # C# (Mono)
314+
... b'''
315+
... using System;
316+
...
317+
... public class HelloWorld
318+
... {
319+
... public static void Main(string[] args)
320+
... {
321+
... Console.WriteLine ("Hello Mono World");
322+
... }
323+
... }
324+
... ''',
325+
... [
326+
... (b'', b'Hello Mono World')
327+
... ]
328+
... )
329+
[
330+
[
331+
(<Status.AC: 'Accepted'>, (b'Hello Mono World\n', b''), 0.02)
332+
],
333+
b'Microsoft (R) Visual C# Compiler version 3.5.0-beta1-19606-04 (d2bd58c6)\n'
334+
b'Copyright (C) Microsoft Corporation. All rights reserved.\n'
335+
b'\n'
336+
]
337+
>>> judge(
338+
... Mono(Mono.Language.vb), # Visual Basic (Mono)
339+
... b'''
340+
... Imports System
341+
...
342+
... Module HelloWorld
343+
... Sub Main()
344+
... Console.WriteLine("Hello World!")
345+
... End Sub
346+
... End Module
347+
... ''',
348+
... [
349+
... (b'', b'Hello World!')
350+
... ]
351+
... )
352+
[
353+
[
354+
(<Status.AC: 'Accepted'>, (b'Hello World!\n', b''), 0.024)
355+
],
356+
b'Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.7 - tarball)\n'
357+
b'Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.\n'
358+
b'\n'
359+
b"Assembly 'mono, Version=0.0, Culture=neutral, PublicKeyToken=null' saved successfully to '/dockerjudge/0/mono.exe'.\r\n"
360+
b'Compilation successful\r\n'
361+
b'Compilation took 00:00:00.0000000\n'
362+
]
309363
```
310364

311365

dockerjudge/processor.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,32 @@ def __init__(self, version=None, filenames=None, options=None):
131131
self.judge = f"./{fns.get('bin', 'main')}"
132132

133133

134+
class Mono(Processor):
135+
'Mono'
136+
137+
class Language(_Language):
138+
'Programming language, C# or Visual Basic'
139+
vb = 'Visual Basic'
140+
csharp = 'C#'
141+
142+
@classmethod
143+
def _get_language(cls, language):
144+
return super().__get_language(language, cls.csharp)
145+
146+
def __init__(self, language=None, version=None):
147+
lang = self.Language._get_language(language)
148+
149+
self.image = self._get_image_with_tag('mono', version)
150+
self.source = f'''mono.{
151+
{self.Language.csharp: 'cs', self.Language.vb: 'vb'}[lang]
152+
}'''
153+
self.compile = [{self.Language.csharp: 'csc',
154+
self.Language.vb: 'vbnc'}[lang],
155+
self.source]
156+
self.after_compile = ['rm', self.source]
157+
self.judge = 'mono mono.exe'
158+
159+
134160
class Node(Processor):
135161
'Node.js®'
136162

test_dockerjudge.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66

77
from dockerjudge import judge
8-
from dockerjudge.processor import (Bash, Clang, GCC, Go, Node, OpenJDK,
8+
from dockerjudge.processor import (Bash, Clang, GCC, Go, Mono, Node, OpenJDK,
99
PHP, PyPy, Python, Ruby)
1010
from dockerjudge.status import Status
1111

@@ -397,5 +397,34 @@ def test_ruby(self):
397397
self.assertEqual(result[0][0][0], Status.AC)
398398

399399

400+
class TestDotNet(unittest.TestCase):
401+
402+
def test_csharp(self):
403+
result = judge(Mono(Mono.Language.csharp), b'''
404+
using System;
405+
406+
public class HelloWorld
407+
{
408+
public static void Main(string[] args)
409+
{
410+
Console.WriteLine ("Hello Mono World");
411+
}
412+
}
413+
''', [(b'', b'Hello Mono World')])
414+
self.assertEqual(result[0][0][0], Status.AC)
415+
416+
def test_vb(self):
417+
result = judge(Mono(Mono.Language.vb), b'''
418+
Imports System
419+
420+
Module HelloWorld
421+
Sub Main()
422+
Console.WriteLine("Hello World!")
423+
End Sub
424+
End Module
425+
''', [(b'', b'Hello World!')])
426+
self.assertEqual(result[0][0][0], Status.AC)
427+
428+
400429
if __name__ == '__main__':
401430
unittest.main()

0 commit comments

Comments
 (0)