diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-13 02:06:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-15 10:06:21 +0900 |
| commit | 8e9dfdbabe0f721e64fd39baa3a0f388c81b65ad (patch) | |
| tree | 6c724cfbeaea94478b542560fa3b40e9f7467330 | |
| parent | 80e1d0fc957a2f254ca94232cca0269567888ddb (diff) | |
| download | ducc-8e9dfdbabe0f721e64fd39baa3a0f388c81b65ad.tar.gz ducc-8e9dfdbabe0f721e64fd39baa3a0f388c81b65ad.tar.zst ducc-8e9dfdbabe0f721e64fd39baa3a0f388c81b65ad.zip | |
feat: add 2 example files
| -rw-r--r-- | examples/fizzbuzz.c | 14 | ||||
| -rw-r--r-- | examples/hello.c | 5 | ||||
| -rw-r--r-- | tests/all.sh | 21 | ||||
| -rw-r--r-- | tests/ex_fizzbuzz.sh | 106 | ||||
| -rw-r--r-- | tests/ex_hello.sh | 7 | ||||
| -rw-r--r-- | tests/test_example.sh | 19 |
6 files changed, 164 insertions, 8 deletions
diff --git a/examples/fizzbuzz.c b/examples/fizzbuzz.c new file mode 100644 index 0000000..c24ce89 --- /dev/null +++ b/examples/fizzbuzz.c @@ -0,0 +1,14 @@ +int printf(const char*, ...); + +int main() { + for (int i = 1; i <= 100; i++) { + if (i % 15 == 0) + printf("FizzBuzz\n"); + else if (i % 3 == 0) + printf("Fizz\n"); + else if (i % 5 == 0) + printf("Buzz\n"); + else + printf("%d\n", i); + } +} diff --git a/examples/hello.c b/examples/hello.c new file mode 100644 index 0000000..5dce624 --- /dev/null +++ b/examples/hello.c @@ -0,0 +1,5 @@ +int printf(const char*, ...); + +int main() { + printf("Hello, World!\n"); +} diff --git a/tests/all.sh b/tests/all.sh index 70776cf..ce7ab6d 100644 --- a/tests/all.sh +++ b/tests/all.sh @@ -2,13 +2,18 @@ set -e rm -rf tests/tmp mkdir -p tests/tmp -for i in $(seq 1 999); do - testcase=$(printf '%03d' $i) + +for filename in tests/*.sh; do + testcase_="$(basename "$filename")" + testcase="${testcase_/%.sh/}" test_file="tests/$testcase.sh" - if [[ -f "$test_file" ]]; then - bash tests/run.sh "$testcase" - else - echo "All tests passed." - exit - fi + case "$testcase" in + all|run|test_*) + ;; + *) + bash tests/run.sh "$testcase" + ;; + esac done + +echo "All tests passed." diff --git a/tests/ex_fizzbuzz.sh b/tests/ex_fizzbuzz.sh new file mode 100644 index 0000000..03d1078 --- /dev/null +++ b/tests/ex_fizzbuzz.sh @@ -0,0 +1,106 @@ +set -e + +cat <<'EOF' > expected +1 +2 +Fizz +4 +Buzz +Fizz +7 +8 +Fizz +Buzz +11 +Fizz +13 +14 +FizzBuzz +16 +17 +Fizz +19 +Buzz +Fizz +22 +23 +Fizz +Buzz +26 +Fizz +28 +29 +FizzBuzz +31 +32 +Fizz +34 +Buzz +Fizz +37 +38 +Fizz +Buzz +41 +Fizz +43 +44 +FizzBuzz +46 +47 +Fizz +49 +Buzz +Fizz +52 +53 +Fizz +Buzz +56 +Fizz +58 +59 +FizzBuzz +61 +62 +Fizz +64 +Buzz +Fizz +67 +68 +Fizz +Buzz +71 +Fizz +73 +74 +FizzBuzz +76 +77 +Fizz +79 +Buzz +Fizz +82 +83 +Fizz +Buzz +86 +Fizz +88 +89 +FizzBuzz +91 +92 +Fizz +94 +Buzz +Fizz +97 +98 +Fizz +Buzz +EOF + +bash ../../test_example.sh fizzbuzz diff --git a/tests/ex_hello.sh b/tests/ex_hello.sh new file mode 100644 index 0000000..3c9e13b --- /dev/null +++ b/tests/ex_hello.sh @@ -0,0 +1,7 @@ +set -e + +cat <<'EOF' > expected +Hello, World! +EOF + +bash ../../test_example.sh hello diff --git a/tests/test_example.sh b/tests/test_example.sh new file mode 100644 index 0000000..d5feaab --- /dev/null +++ b/tests/test_example.sh @@ -0,0 +1,19 @@ +filename="../../../examples/$1.c" + +"$ducc" "$filename" > main.s +if [[ $? -ne 0 ]]; then + exit 1 +fi +gcc -Wl,-z,noexecstack -o a.out main.s +if [[ ! -f input ]]; then + touch input +fi +./a.out "$@" < input > output +exit_code=$? + +if [[ $exit_code -ne 0 ]]; then + echo "invalid exit code: $exit_code" >&2 + exit 1 +fi + +diff -u expected output |
