Loading tests/assignment-1/a1-tests.bats +29 −0 Original line number Diff line number Diff line Loading @@ -159,34 +159,63 @@ setup() { } @test "[EXERCISE 20] File 'coins.txt' was created" { bash -c "$(awk '/# EXERCISE 20$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)" assert_file_exists './coins.txt' assert_file_not_empty './coins.txt' } @test "[EXERCISE 21] All coins from 'USA' were printed" { # Manually fail the test if coints.txt is empty if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;3p;8p;9p;10p;11p;12p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 21$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 22] All coins ending with 'r' were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '8p;9p;11p;12p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 22$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 23] The first and last coins were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;13p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 23$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 24] All coins that have a year greater than 1980 were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;3p;4p;6p;7p;8p;9p;10p;11p;12p;13p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 24$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 25] All coins made of gold were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;2p;4p;5p;6p;7p;9p;12p;13p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 25$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" Loading Loading
tests/assignment-1/a1-tests.bats +29 −0 Original line number Diff line number Diff line Loading @@ -159,34 +159,63 @@ setup() { } @test "[EXERCISE 20] File 'coins.txt' was created" { bash -c "$(awk '/# EXERCISE 20$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)" assert_file_exists './coins.txt' assert_file_not_empty './coins.txt' } @test "[EXERCISE 21] All coins from 'USA' were printed" { # Manually fail the test if coints.txt is empty if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;3p;8p;9p;10p;11p;12p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 21$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 22] All coins ending with 'r' were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '8p;9p;11p;12p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 22$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 23] The first and last coins were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;13p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 23$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 24] All coins that have a year greater than 1980 were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;3p;4p;6p;7p;8p;9p;10p;11p;12p;13p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 24$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" } @test "[EXERCISE 25] All coins made of gold were printed" { if [ ! -s ./coins.txt ]; then echo "coins.txt is empty" exit 1 fi expected_output="$(sed -n '1p;2p;4p;5p;6p;7p;9p;12p;13p' ./coins.txt)" actual_output="$(bash -c "$(awk '/# EXERCISE 25$/{flag=1; next} /# EXERCISE/{flag=0} flag' ./commands.sh)")" assert_equal "$actual_output" "$expected_output" Loading