Commit 3bd1f8e8 authored by Giannis Kepas's avatar Giannis Kepas
Browse files

assignment-3 tests

parent c82daf31
Loading
Loading
Loading
Loading

assignment-3-tests.yml

0 → 100644
+34 −0
Original line number Diff line number Diff line
default:
  image: debian:bookworm-slim
  before_script:
    - apt-get update && apt-get install -y git
    - git clone --recurse-submodules -j8 https://netsim.cs.uowm.gr/gitlab/operating-systems/os-tests.git
    - chmod +x ./*.sh

stages:
  - test

test-task-1:
  stage: test
  script:
    - ./os-tests/bats/bats-core/bin/bats os-tests/tests/assignment-3/a3-task1.bats

test-task-2:
  stage: test
  script:
    - ./os-tests/bats/bats-core/bin/bats os-tests/tests/assignment-3/a3-task2.bats

test-task-3:
  stage: test
  script:
    - ./os-tests/bats/bats-core/bin/bats os-tests/tests/assignment-3/a3-task3.bats

test-task-4:
  stage: test
  script:
    - ./os-tests/bats/bats-core/bin/bats os-tests/tests/assignment-3/a3-task4.bats

test-task-5:
  stage: test
  script:
    - ./os-tests/bats/bats-core/bin/bats os-tests/tests/assignment-3/a3-task5.bats
+18 −0
Original line number Diff line number Diff line
#!/usr/bin/env bats

setup() {
    load '../../bats/bats-support/load'
    load '../../bats/bats-assert/load'
}

@test "[TASK 1] test 1: should not exit for input 'abcdef.txt'" {
    # Run the script with invalid input and ensure it doesn't exit immediately
    run timeout 2 ./task-1.sh <<< "abcdef.txt"
    [ "$status" -ne 0 ] # Ensure the script is still running (non-zero exit code)
}

@test "[TASK 1] test 2: should exit for input 'task-1.sh'" {
    # Run the script and provide the input
    run ./task-1.sh <<< "task-1.sh"
    [ "$status" -eq 0 ] # Ensure the script exits successfully
}
+24 −0
Original line number Diff line number Diff line
#!/usr/bin/env bats

setup() {
    load '../../bats/bats-support/load'
    load '../../bats/bats-assert/load'
}

@test "[TASK 2] test 1: should not exit for invalid number '15'" {
    # Run the script with invalid input and ensure it doesn't exit immediately
    run timeout 2 ./task-2.sh <<< "15"
    [ "$status" -ne 0 ] # Ensure the script is still running (non-zero exit code)
}

@test "[TASK 2] test 2: should exit for valid input '25'" {
    # Run the script and provide the input
    run ./task-2.sh <<< "25"
    [ "$status" -eq 0 ] # Ensure the script exits successfully
}

@test "[TASK 2] test 3: should handle multiple invalid inputs before valid input" {
    # Simulate multiple invalid inputs followed by a valid one
    run ./task-2.sh <<< $'10\n40\n25'
    [ "$status" -eq 0 ] # Ensure the script exits successfully
}
+27 −0
Original line number Diff line number Diff line
#!/usr/bin/env bats

setup() {
    load '../../bats/bats-support/load'
    load '../../bats/bats-assert/load'
}

teardown() {
    find ./ -iname 'file[0-9]*' -type f -delete
}

@test "[TASK 3] test 1: should create 150 files with correct content" {
    run ./task-3.sh
    [ "$status" -eq 0 ] # Ensure the script exits successfully

    # Check that 150 files were created
    file_count=$(find ./ -iname 'file[0-9]*' -type f | wc -l)
    [ "$file_count" -eq 150 ]

    # Verify each file contains its respective number
    for i in $(seq 1 150); do
        file_name="file$i"
        [ -f "$file_name" ] # Ensure the file exists
        run cat "$file_name"
        [ "$output" -eq "$i" ] # Ensure the content matches the file number
    done
}
+13 −0
Original line number Diff line number Diff line
#!/usr/bin/env bats

setup() {
    load '../../bats/bats-support/load'
    load '../../bats/bats-assert/load'
}

@test "[TASK 4] test 1: should calculate the total and average correctly" {
    run ./task-4.sh

    assert_output --partial "103400"
    assert_output --partial "20680"
}
Loading