Skip to content

Commit

Permalink
tasks: add test for ordering around a root
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Nov 23, 2024
1 parent bc2b55d commit 6de413b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions devenv-tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,51 @@ mod test {
Ok(())
}

// Ensure that tasks before and after a root are run in the correct order.
#[tokio::test]
async fn test_non_root_before_and_after() -> Result<(), Error> {
let script1 = create_basic_script("1")?;
let script2 = create_basic_script("2")?;
let script3 = create_basic_script("3")?;

let tasks = Tasks::new(
Config::try_from(json!({
"roots": ["myapp:task_2"],
"tasks": [
{
"name": "myapp:task_1",
"command": script1.to_str().unwrap(),
"before": [ "myapp:task_2"]
},
{
"name": "myapp:task_2",
"command": script2.to_str().unwrap()
},
{
"name": "myapp:task_3",
"after": ["myapp:task_2"],
"command": script3.to_str().unwrap()
},
]
}))
.unwrap(),
)
.await?;
tasks.run().await;

let task_statuses = inspect_tasks(&tasks).await;
let task_statuses = task_statuses.as_slice();
assert_matches!(
task_statuses,
[
(name1, TaskStatus::Completed(TaskCompleted::Success(_, _))),
(name2, TaskStatus::Completed(TaskCompleted::Success(_, _))),
(name3, TaskStatus::Completed(TaskCompleted::Success(_, _)))
] if name1 == "myapp:task_1" && name2 == "myapp:task_2" && name3 == "myapp:task_3"
);
Ok(())
}

#[tokio::test]
async fn test_dependency_failure() -> Result<(), Error> {
let failing_script = create_script("#!/bin/sh\necho 'Failing task' && exit 1")?;
Expand Down

0 comments on commit 6de413b

Please sign in to comment.