Skip to content

Commit

Permalink
feat: Add a utility method to know if a rule is a regular rule (#42)
Browse files Browse the repository at this point in the history
Closes #27.
  • Loading branch information
theofidry authored Oct 1, 2023
1 parent 6be4ed9 commit 2982140
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function isPhony(): bool
return self::PHONY_TARGET === $this->target;
}

public function isRegularRule(): bool
{
return !$this->isPhony() && !$this->isComment();
}

/**
* @param list<string> $prerequisites
*/
Expand Down
48 changes: 48 additions & 0 deletions tests/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,54 @@ public static function commandCommentProvider(): iterable
];
}

/**
* @dataProvider regularRuleProvider
*/
public function test_it_can_detect_the_rule_is_a_regular_rule(
Rule $rule,
bool $expected
): void {
self::assertSame($expected, $rule->isRegularRule());
}

public static function regularRuleProvider(): iterable
{
yield 'rule' => [
new Rule('command', ['progA', 'progB']),
true,
];

yield 'PHONY rule' => [
Rule::createPhony(['progA', 'progB']),
false,
];

yield 'rule with Makefile comment' => [
new Rule('command', ['#progA progB']),
false,
];

yield 'rule with command comment' => [
new Rule('command', ['##progA progB']),
false,
];

yield 'rule with extra comment marker' => [
new Rule('command', ['###progA progB']),
false,
];

yield 'PHONY rule with Makefile comment' => [
Rule::createPhony(['#progA progB']),
false,
];

yield 'rule with no pre-requisite' => [
new Rule('command', []),
true,
];
}

public function test_it_can_create_a_phony_rule(): void
{
$rule = Rule::createPhony(['progA', 'progB']);
Expand Down

0 comments on commit 2982140

Please sign in to comment.