diff --git a/HelloWorld.bash b/HelloWorld.bash index 1c1bd38..f0da9b6 100755 --- a/HelloWorld.bash +++ b/HelloWorld.bash @@ -1,21 +1,21 @@ #!/usr/bin/bash # File: HelloWorld.bash -# -# Description: This file exemplifies printing 'Hello world!' in bash. -# +# +# Description: This file exemplifies printing 'Hello, World!' in bash. +# # Package: AniNIX/HelloWorld # Copyright: WTFPL -# +# # Author: DarkFeather -### String to print -export _helloWorld="Hello world!" +### String to print +export _helloWorld="Hello, World!" -### Prints 'Hello world!' +### Prints 'Hello, World!' ### -function main() { +function main() { printf "$_helloWorld""\n" } diff --git a/HelloWorld.c b/HelloWorld.c index e677cd4..1c3dcd2 100644 --- a/HelloWorld.c +++ b/HelloWorld.c @@ -2,19 +2,19 @@ /* * File: HelloWorld.c - * - * Description: This file exemplifies printing 'Hello world!' in C. - * + * + * Description: This file exemplifies printing 'Hello, World!' in C. + * * Package: AniNIX/HelloWorld * Copyright: WTFPL - * + * * Author: DarkFeather */ -static char * message = "Hello world!"; +static char * message = "Hello, World!"; /// -/// Prints 'Hello world!' +/// Prints 'Hello, World!' /// void HelloWorld() { printf("%s\n",message); diff --git a/HelloWorld.cs b/HelloWorld.cs index 30cff17..2fd5fc7 100644 --- a/HelloWorld.cs +++ b/HelloWorld.cs @@ -2,12 +2,12 @@ using System; /* * File: HelloWorld.cs - * - * Description: This file exemplifies printing 'Hello world!' in C#. - * + * + * Description: This file exemplifies printing 'Hello, World!' in C#. + * * Package: AniNIX/HelloWorld * Copyright: WTFPL - * + * * Author: DarkFeather */ @@ -17,12 +17,12 @@ namespace AniNIX { public sealed class HelloWorld { // String to print - private static String _helloWorld="Hello world!"; + private static String _helloWorld="Hello, World!"; /// - /// Print 'Hello world!' + /// Print 'Hello, World!' /// - public static void PrintHelloWorld() { + public static void PrintHelloWorld() { Console.WriteLine(_helloWorld); } diff --git a/HelloWorld.java b/HelloWorld.java index 79741e4..f286336 100644 --- a/HelloWorld.java +++ b/HelloWorld.java @@ -2,30 +2,30 @@ import java.lang.System; /* * File: HelloWorld.java - * - * Description: This file exemplifies printing 'Hello world!' in Java. - * + * + * Description: This file exemplifies printing 'Hello, World!' in Java. + * * Package: AniNIX/HelloWorld * Copyright: WTFPL - * + * * Author: DarkFeather */ /// This class is used exemplify coding standard in Java -public class HelloWorld { +public class HelloWorld { // String to print - private static String _helloWorld = "Hello world!"; + private static String _helloWorld = "Hello, World!"; /// - /// Print 'Hello world!' + /// Print 'Hello, World!' /// public static void PrintHelloWorld() { System.out.println(_helloWorld); } - - /// MAIN - public static void main(String[] args) { + + /// MAIN + public static void main(String[] args) { PrintHelloWorld(); } } diff --git a/HelloWorld.php b/HelloWorld.php index 33f5b8f..2c5758e 100644 --- a/HelloWorld.php +++ b/HelloWorld.php @@ -1,22 +1,22 @@ ### String to print -$_helloWorld="Hello world!"; +$_helloWorld="Hello, World!"; ### -### Prints 'Hello world!' +### Prints 'Hello, World!' ### -function PrintHelloWorld() { +function PrintHelloWorld() { global $_helloWorld; echo $_helloWorld."\n"; diff --git a/HelloWorld.pl b/HelloWorld.pl index 0ad50cc..ea5db72 100755 --- a/HelloWorld.pl +++ b/HelloWorld.pl @@ -1,19 +1,19 @@ #!/usr/bin/perl # File: HelloWorld.pl -# -# Description: This file exemplifies printing 'Hello world!' in perl. -# +# +# Description: This file exemplifies printing 'Hello, World!' in perl. +# # Package: AniNIX/HelloWorld # Copyright: WTFPL -# +# # Author: DarkFeather ### -### Prints 'Hello world!' +### Prints 'Hello, World!' ### sub PrintHelloWorld { - print "Hello world!\n" + print "Hello, World!\n" } ### MAIN diff --git a/HelloWorld.py b/HelloWorld.py index 7eee25b..ab677b5 100755 --- a/HelloWorld.py +++ b/HelloWorld.py @@ -1,21 +1,21 @@ #!/usr/bin/env python3 # File: HelloWorld.py -# -# Description: This file exemplifies printing 'Hello world!' in python. -# +# +# Description: This file exemplifies printing 'Hello, World!' in python. +# # Package: AniNIX/HelloWorld # Copyright: WTFPL -# +# # Author: DarkFeather -### String to print -_helloWorld='Hello world!' +### String to print +_helloWorld='Hello, World!' ### -### Prints 'Hello world!' +### Prints 'Hello, World!' ### -def PrintHelloWorld(): +def PrintHelloWorld(): print(_helloWorld) ### Main diff --git a/Makefile b/Makefile index 079740f..90e5bd8 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ checkperm: c: HelloWorld.c /usr/bin/gcc gcc -o HelloWorld HelloWorld.c -java: HelloWorld.java /usr/lib/jvm/java-19-openjdk/bin/javac /usr/lib/jvm/java-19-openjdk/bin/java - /usr/lib/jvm/java-19-openjdk/bin/javac HelloWorld.java +java: HelloWorld.java /usr/bin/javac /usr/bin/java + /usr/bin/javac HelloWorld.java bash: HelloWorld.bash /usr/bin/bash #bash HelloWorld.bash diff --git a/README.md b/README.md index 8c3511d..d23014c 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ -This project is tracking basic standards of reference for getting started with various programming languages. That standard has always been a program that prints "Hello world!" +This project is tracking basic standards of reference for getting started with various programming languages. That standard has always been a program that prints "Hello, World!" # Etymology A program called ["Hello, World!"](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program) has been a mainstay of computing for a long time, with some thinking it began with BCPL in 1967. Regardless, it is a common teaching tool for new programmers, and it is a way for a language to announce itself to the world. # Relevant Files and Software -The relevant software for this is any executing engine for a language included in the project. For languages like C, they compile into local executables -- languages like Java & C# create compiled entities that need to execute within their runtime. Others, like Python & PHP, don't compile but execute within their respective binaries. Check the [test_unit.py](/AniNIX/HelloWorld/src/branch/main/tests/test_unit.py) file for more details on invocation. +The relevant software for this is any executing engine for a language included in the project. For languages like C, they compile into local executables -- languages like Java & C# create compiled entities that need to execute within their runtime. Others, like Python & PHP, don't compile but execute within their respective binaries. Check the [test units](/AniNIX/HelloWorld/src/branch/main/tests) file for more details on invocation. + +## Java + +Per [ArchWiki's notes on Java](https://wiki.archlinux.org/title/Java#Installation), you need to use `archlinux-java` to set your java environment. We typically use the latest Java available. # Available Clients diff --git a/precommit-hooks/coverage.bash b/precommit-hooks/coverage.bash new file mode 100644 index 0000000..f75c57e --- /dev/null +++ b/precommit-hooks/coverage.bash @@ -0,0 +1,22 @@ +#!/bin/bash +# +# Find that we have tests for each file. + +retcode=0 +for language in `ls -1 ./HelloWorld.* | cut -f 3 -d '.'`; do + + # Ensure there's a test file. + if [ ! -f tests/test_"${language}".py ]; then + echo "${language^} is missing a test file." + retcode=1 + else + # Ensure that each test is defined. + if ! grep "^def test_${language}():$" tests/test_"${language}".py &>/dev/null; then + echo "${language^} doesn't have the right test definition." + retcode=1 + fi + fi + +done + +exit $retcode diff --git a/tests/global_fns.py b/tests/global_fns.py index ccf844d..b4e6a5a 100644 --- a/tests/global_fns.py +++ b/tests/global_fns.py @@ -7,7 +7,7 @@ def checkOutput(output): Ensure hello world is in string. return: whether hello world is present """ - return output == 'Hello world!\n' + return output == 'Hello, World!\n' def runCommand(command): """ @@ -16,12 +16,11 @@ def runCommand(command): return: Whether retcode is 0 """ fh = os.popen(command, mode='r', buffering=-1) - output = fh.read() + fh.read() retcode = fh.close() - assert retcode == None + return retcode == None - -def runCommandAndOutputCheck(command): +def runCommandAndCheckOutput(command): """ Define a function to run a shell command and ensure output is correct param command: command @@ -30,4 +29,4 @@ def runCommandAndOutputCheck(command): fh = os.popen(command, mode='r', buffering=-1) output = fh.read() retcode = fh.close() - assert retcode == None and CheckOutput(output) + return retcode == None and checkOutput(output) diff --git a/tests/test_bash.py b/tests/test_bash.py new file mode 100644 index 0000000..69ae8ea --- /dev/null +++ b/tests/test_bash.py @@ -0,0 +1,6 @@ +import os +import shutil +from tests.global_fns import * + +def test_bash(): + runCommandAndCheckOutput("./HelloWorld.bash") diff --git a/tests/test_c.py b/tests/test_c.py index 6bde8cb..9a17717 100644 --- a/tests/test_c.py +++ b/tests/test_c.py @@ -1,24 +1,6 @@ import os -import re import shutil - from tests.global_fns import * -def test_compile_c(): - fh = os.popen("gcc -o HelloWorld ./HelloWorld.c", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None - - def test_c(): - fh = os.popen("./HelloWorld", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and checkOutput(output) - -def test_c_cleanup(): - fh = os.popen("rm ./HelloWorld", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None + runCommandAndCheckOutput("./HelloWorld") diff --git a/tests/test_cs.py b/tests/test_cs.py new file mode 100644 index 0000000..6a9b7fb --- /dev/null +++ b/tests/test_cs.py @@ -0,0 +1,6 @@ +import os +import shutil +from tests.global_fns import * + +def test_cs(): + runCommandAndCheckOutput("mono ./HelloWorld.exe") diff --git a/tests/test_java.py b/tests/test_java.py new file mode 100644 index 0000000..a65bffb --- /dev/null +++ b/tests/test_java.py @@ -0,0 +1,6 @@ +import os +import shutil +from tests.global_fns import * + +def test_java(): + runCommandAndCheckOutput("/usr/bin/java HelloWorld") diff --git a/tests/test_php.py b/tests/test_php.py new file mode 100644 index 0000000..239e5d7 --- /dev/null +++ b/tests/test_php.py @@ -0,0 +1,6 @@ +import os +import shutil +from tests.global_fns import * + +def test_php(): + runCommandAndCheckOutput("php ./HelloWorld.php") diff --git a/tests/test_pl.py b/tests/test_pl.py new file mode 100644 index 0000000..37e26a1 --- /dev/null +++ b/tests/test_pl.py @@ -0,0 +1,6 @@ +import os +import shutil +from tests.global_fns import * + +def test_pl(): + runCommandAndCheckOutput("") diff --git a/tests/test_py.py b/tests/test_py.py new file mode 100644 index 0000000..4e4b145 --- /dev/null +++ b/tests/test_py.py @@ -0,0 +1,6 @@ +import os +import shutil +from tests.global_fns import * + +def test_py(): + runCommandAndCheckOutput("./HelloWorld.py") diff --git a/tests/test_unit.py b/tests/test_unit.py deleted file mode 100644 index e101ee5..0000000 --- a/tests/test_unit.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import re -import shutil - -def CheckOutput(output): - return output == 'Hello world!\n' - -def test_make(): - print(os.getcwd()) - fh = os.popen("/bin/bash -c 'make compile'", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None - -def test_c(): - print(os.getcwd()) - fh = os.popen("./HelloWorld", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) - -def test_cs(): - print(os.getcwd()) - fh = os.popen("mono ./HelloWorld.exe", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) - -def test_java(): - print(os.getcwd()) - fh = os.popen("/usr/lib/jvm/java-19-openjdk/bin/java HelloWorld", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) - -def test_bash(): - print(os.getcwd()) - fh = os.popen("./HelloWorld.bash", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) - -def test_perl(): - print(os.getcwd()) - fh = os.popen("./HelloWorld.pl", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) - -def test_php(): - print(os.getcwd()) - fh = os.popen("php ./HelloWorld.php", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) - -def test_python(): - print(os.getcwd()) - fh = os.popen("./HelloWorld.py", mode='r', buffering=-1) - output = fh.read() - retcode = fh.close() - assert retcode == None and CheckOutput(output) -