tests/testthat/test-wait_on_jobs.R

test_that(
  "wait_on_jobs dry-run produces expected command string",
  {
    expect_message(
      wait_on_jobs(
        job_pattern         = "abcde"
        , jobname_nchar     = 5L
        , initial_sleep_sec = 5
        , file_list         = NULL
        , obj               = NULL
        , resub             = 0
        , perl              = TRUE
        , dryrun            = TRUE
      ),
      regexp = "sacct --format=JobID%16,JobName%5,User%20,State%16,ExitCode,NodeList%27,Partition%12,Account%20 | grep 'RUNNING\\|PENDING' | grep -P abcde"
    )
    
    expect_message(
      wait_on_jobs(
        job_pattern         = "abcde"
        , jobname_nchar     = 5L
        , initial_sleep_sec = 5
        , file_list         = NULL
        , obj               = NULL
        , resub             = 0
        , perl              = FALSE
        , dryrun            = TRUE
      ),
      regexp = "sacct --format=JobID%16,JobName%5,User%20,State%16,ExitCode,NodeList%27,Partition%12,Account%20 | grep 'RUNNING\\|PENDING' | grep abcde"
    )
    
  }
)

test_that(
  "wait_on_jobs produces correct warning",
  {
    # capture message as well for cleaner test pane output
    wait_on_jobs(
      job_pattern         = "abcde"
      , jobname_nchar     = 4L
      , initial_sleep_sec = 5
      , file_list         = NULL
      , obj               = NULL
      , resub             = 0
      , perl              = TRUE
      , dryrun            = TRUE
    ) %>% 
      expect_warning(regexp = "The job pattern abcde exceeds the current max of 4 characters, wait_on_jobs may not track this job correctly.") %>%
      expect_message(regexp = "sacct --format=JobID%16,JobName%4,User%20,State%16,ExitCode,NodeList%27,Partition%12,Account%20 | grep 'RUNNING\\|PENDING' | grep -P abcde")
  }
)
epi-sam/SamsElves documentation built on June 12, 2025, 7 a.m.