Loading .gitmodules 0 → 100644 +9 −0 Original line number Diff line number Diff line [submodule "test/bats"] path = test/bats url = https://github.com/bats-core/bats-core.git [submodule "test/test_helper/bats-support"] path = test/test_helper/bats-support url = https://github.com/bats-core/bats-support.git [submodule "test/test_helper/bats-assert"] path = test/test_helper/bats-assert url = https://github.com/bats-core/bats-assert.git exercise-2-tests.shdeleted 100755 → 0 +0 −71 Original line number Diff line number Diff line #!/bin/bash set -euo pipefail # Uncomment the line below to enable debugging #set -x error_handler() { line="*** TESTS HAVE FAILED ***" echo -e "\e[01;31m$line\e[0m" 1>&2 } trap error_handler ERR # === Exercise 1 Tests === # Task 1 - Test 1 # should print 'The number is odd.' for input 1 if echo "1" | ./task-1.sh | grep -v 'odd'; then echo "Task 1 - Test 1: Failed" echo "Expected: 'The number is odd.'" echo "Got: $(echo "1" | ./task-1.sh)" exit 1 else echo "Task 1 - Test 1: Passed" fi # Task 1 - Test 2 # should print 'The number is even.' for input 4 if echo "4" | ./task-1.sh | grep -v 'even'; then echo "Task 1 - Test 1: Failed" echo "Expected: 'The number is even.'" echo "Got: $(echo "4" | ./task-1.sh)" exit 1 else echo "Task 1 - Test 2: Passed" fi # Task 1 - Test 3 # should print 'The number is odd.' for input 7 if echo "7" | ./task-1.sh | grep -v 'odd'; then echo "Task 1 - Test 1: Failed" echo "Expected: 'The number is odd.'" echo "Got: $(echo "7" | ./task-1.sh)" exit 1 else echo "Task 1 - Test 3: Passed" fi # Task 2 - Test 1 # should print the number of files in /etc if [ "$(./task-2.sh)" -ne "$(ls -1q /etc/ | wc -l)" ]; then echo "Task 2 - Test 1: Failed" echo "Expected: $(ls -1q /etc/ | wc -l)" echo "Got: $(./task-2.sh)" exit 1 else echo "Task 2 - Test 1: Passed" fi # Task 3 - Test 1 # should print the number of files starting with 'k' if [ "$(./task-3.sh)" -ne "$(find . -name "k*" | wc -l)" ]; then echo "Task 3 - Test 1: Failed" echo "Expected: $(find . -name "k*" | wc -l)" echo "Got: $(./task-3.sh)" exit 1 else echo "Task 3 - Test 1: Passed" fi echo "All tests passed!" exit 0 No newline at end of file exercise-2-tests.ymldeleted 100644 → 0 +0 −10 Original line number Diff line number Diff line image: docker:latest stages: - test test: stage: test script: - for filename in ./*.sh; do chmod +x "${filename}"; done - ./exercise-2-tests.sh bats @ 89a7fae3 Original line number Diff line number Diff line Subproject commit 89a7fae3b651d5c2f42a3874ec32e821014814eb test/exercise-1-tests.bats 0 → 100644 +21 −0 Original line number Diff line number Diff line #!/usr/bin/env bats setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' } @test "task 1: should print 'odd' for input '1'" { run ./task-1.sh <<< "1" assert_output --partial 'odd' } @test "task 1: should print 'even' for input '2'" { run ./task-1.sh <<< "1" assert_output --partial 'odd' } @test "task 1: should print 'odd' for input '5'" { run ./task-1.sh <<< "1" assert_output --partial 'odd' } Loading
.gitmodules 0 → 100644 +9 −0 Original line number Diff line number Diff line [submodule "test/bats"] path = test/bats url = https://github.com/bats-core/bats-core.git [submodule "test/test_helper/bats-support"] path = test/test_helper/bats-support url = https://github.com/bats-core/bats-support.git [submodule "test/test_helper/bats-assert"] path = test/test_helper/bats-assert url = https://github.com/bats-core/bats-assert.git
exercise-2-tests.shdeleted 100755 → 0 +0 −71 Original line number Diff line number Diff line #!/bin/bash set -euo pipefail # Uncomment the line below to enable debugging #set -x error_handler() { line="*** TESTS HAVE FAILED ***" echo -e "\e[01;31m$line\e[0m" 1>&2 } trap error_handler ERR # === Exercise 1 Tests === # Task 1 - Test 1 # should print 'The number is odd.' for input 1 if echo "1" | ./task-1.sh | grep -v 'odd'; then echo "Task 1 - Test 1: Failed" echo "Expected: 'The number is odd.'" echo "Got: $(echo "1" | ./task-1.sh)" exit 1 else echo "Task 1 - Test 1: Passed" fi # Task 1 - Test 2 # should print 'The number is even.' for input 4 if echo "4" | ./task-1.sh | grep -v 'even'; then echo "Task 1 - Test 1: Failed" echo "Expected: 'The number is even.'" echo "Got: $(echo "4" | ./task-1.sh)" exit 1 else echo "Task 1 - Test 2: Passed" fi # Task 1 - Test 3 # should print 'The number is odd.' for input 7 if echo "7" | ./task-1.sh | grep -v 'odd'; then echo "Task 1 - Test 1: Failed" echo "Expected: 'The number is odd.'" echo "Got: $(echo "7" | ./task-1.sh)" exit 1 else echo "Task 1 - Test 3: Passed" fi # Task 2 - Test 1 # should print the number of files in /etc if [ "$(./task-2.sh)" -ne "$(ls -1q /etc/ | wc -l)" ]; then echo "Task 2 - Test 1: Failed" echo "Expected: $(ls -1q /etc/ | wc -l)" echo "Got: $(./task-2.sh)" exit 1 else echo "Task 2 - Test 1: Passed" fi # Task 3 - Test 1 # should print the number of files starting with 'k' if [ "$(./task-3.sh)" -ne "$(find . -name "k*" | wc -l)" ]; then echo "Task 3 - Test 1: Failed" echo "Expected: $(find . -name "k*" | wc -l)" echo "Got: $(./task-3.sh)" exit 1 else echo "Task 3 - Test 1: Passed" fi echo "All tests passed!" exit 0 No newline at end of file
exercise-2-tests.ymldeleted 100644 → 0 +0 −10 Original line number Diff line number Diff line image: docker:latest stages: - test test: stage: test script: - for filename in ./*.sh; do chmod +x "${filename}"; done - ./exercise-2-tests.sh
bats @ 89a7fae3 Original line number Diff line number Diff line Subproject commit 89a7fae3b651d5c2f42a3874ec32e821014814eb
test/exercise-1-tests.bats 0 → 100644 +21 −0 Original line number Diff line number Diff line #!/usr/bin/env bats setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' } @test "task 1: should print 'odd' for input '1'" { run ./task-1.sh <<< "1" assert_output --partial 'odd' } @test "task 1: should print 'even' for input '2'" { run ./task-1.sh <<< "1" assert_output --partial 'odd' } @test "task 1: should print 'odd' for input '5'" { run ./task-1.sh <<< "1" assert_output --partial 'odd' }