Skip to content

Commit

Permalink
Add linter for making sure linux main is kept up to date (#192)
Browse files Browse the repository at this point in the history
* Add linter for making sure linux main is kept up to date

* Print diff output in lint script and stable output testing script

* Sort the files we parse for generating the linux test index. This makes the result stable, caught on CI
  • Loading branch information
rahul-malik authored Mar 20, 2019
1 parent 5e5ed22 commit 02d18ba
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 51 deletions.
88 changes: 43 additions & 45 deletions Tests/CoreTests/LinuxTestIndex.swift
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
// @generated by GenerateTestCaseProvider.swift
// swiftformat:disable all
import XCTest

#if os(Linux)
// Generated Test Extension for StringExtensionsTests
extension StringExtensionsTests {
static var allTests = [
("testUppercaseFirst", testUppercaseFirst),
("testLowercaseFirst", testLowercaseFirst),
("testSuffixSubstring", testSuffixSubstring),
]
}

// Generated Test Extension for ObjectiveCIRTests
extension ObjectiveCIRTests {
static var allTests = [
("testDirtyPropertyOption", testDirtyPropertyOption),
("testDirtyPropertyOptionMultiWord", testDirtyPropertyOptionMultiWord),
("testEnumTypeName", testEnumTypeName),
("testEnumToStringName", testEnumToStringName),
("testEnumFromStringName", testEnumFromStringName),
("testStatementSyntax", testStatementSyntax),
("testMsgSyntax", testMsgSyntax),
("testBlockSyntax", testBlockSyntax),
("testScopeSyntax", testScopeSyntax),
("testNestedScopeSyntax", testNestedScopeSyntax),
("testIfStmt", testIfStmt),
("testElseIfStmt", testElseIfStmt),
("testElseStmt", testElseStmt),
("testIfElseStmt", testIfElseStmt),
]
}

// Generated Test Extension for LanguagesTests
extension LanguagesTests {
static var allTests = [
("testSnakeCaseToCamelCase", testSnakeCaseToCamelCase),
("testSnakeCaseToPropertyName", testSnakeCaseToPropertyName),
("testSnakeCaseToCapitalizedPropertyName", testSnakeCaseToCapitalizedPropertyName),
("testReservedKeywordSubstitution", testReservedKeywordSubstitution),
]
}

// Generated Test Extension for ObjectiveCInitTests
extension ObjectiveCInitTests {
static var allTests = [
("testOneOfInit", testOneOfInit),
]
}
// Generated Test Extension for LanguagesTests
extension LanguagesTests {
static var allTests = [
("testSnakeCaseToCamelCase", testSnakeCaseToCamelCase),
("testSnakeCaseToPropertyName", testSnakeCaseToPropertyName),
("testSnakeCaseToCapitalizedPropertyName", testSnakeCaseToCapitalizedPropertyName),
("testReservedKeywordSubstitution", testReservedKeywordSubstitution)
]
}
// Generated Test Extension for ObjectiveCIRTests
extension ObjectiveCIRTests {
static var allTests = [
("testDirtyPropertyOption", testDirtyPropertyOption),
("testDirtyPropertyOptionMultiWord", testDirtyPropertyOptionMultiWord),
("testEnumTypeName", testEnumTypeName),
("testEnumToStringName", testEnumToStringName),
("testEnumFromStringName", testEnumFromStringName),
("testStatementSyntax", testStatementSyntax),
("testMsgSyntax", testMsgSyntax),
("testBlockSyntax", testBlockSyntax),
("testScopeSyntax", testScopeSyntax),
("testNestedScopeSyntax", testNestedScopeSyntax),
("testIfStmt", testIfStmt),
("testElseIfStmt", testElseIfStmt),
("testElseStmt", testElseStmt),
("testIfElseStmt", testIfElseStmt)
]
}
// Generated Test Extension for ObjectiveCInitTests
extension ObjectiveCInitTests {
static var allTests = [
("testOneOfInit", testOneOfInit)
]
}
// Generated Test Extension for StringExtensionsTests
extension StringExtensionsTests {
static var allTests = [
("testUppercaseFirst", testUppercaseFirst),
("testLowercaseFirst", testLowercaseFirst),
("testSuffixSubstring", testSuffixSubstring)
]
}
#endif
11 changes: 6 additions & 5 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@testable import CoreTests
// @generated - Generated by GeneratedTestCaseProvider.swift
// swiftformat:disable all
import XCTest
@testable import CoreTests

var tests = [XCTestCaseEntry]()
tests += [testCase(StringExtensionsTests.allTests)]
tests += [testCase(ObjectiveCIRTests.allTests)]
tests += [testCase(LanguagesTests.allTests)]
tests += [testCase(ObjectiveCInitTests.allTests)]
tests += [testCase(LanguagesTests.allTests)]
tests += [testCase(ObjectiveCIRTests.allTests)]
tests += [testCase(ObjectiveCInitTests.allTests)]
tests += [testCase(StringExtensionsTests.allTests)]

XCTMain(tests)
3 changes: 3 additions & 0 deletions Utility/GenerateTestCaseProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func printLinuxMain(withClassNames classNames: [String]) -> String {
}.joined(separator: "\n")
return [
"// @generated - Generated by GeneratedTestCaseProvider.swift",
"// swiftformat:disable all",
"import XCTest",
"@testable import CoreTests",
"",
Expand Down Expand Up @@ -91,11 +92,13 @@ func processDirectory(atPath path: String) {
guard path != "" else { return }
if let files = try? FileManager.default.contentsOfDirectory(atPath: path) {
let generatedOutput = files
.sorted()
.map { processFile(withPath: path + "/" + $0) }
.filter { $0 != "" }
.joined(separator: "\n")
let output = [
"// @generated by GenerateTestCaseProvider.swift",
"// swiftformat:disable all",
"import XCTest",
"",
"#if os(Linux)",
Expand Down
30 changes: 30 additions & 0 deletions Utility/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,38 @@

set -eou pipefail

update_current_line() {
printf "\033[1A" # move cursor one line up
printf "\033[K" # delete till end of line
echo "$1"
}

log_err() {
echo "$1"
}

log_success() {
update_current_line "$1"
}

echo "Checking for lint errors with SwiftLint"
swift run swiftlint lint --reporter emoji

echo "Checking for formatting errors with SwiftFormat"
swift run swiftformat --lint .

echo "Checking if linux test index needs to be updated"
readonly TEMP_DIR=$(mktemp -d)
cp -R Tests "${TEMP_DIR}"
cp -R Utility "${TEMP_DIR}"
cp Makefile "${TEMP_DIR}"
(cd "${TEMP_DIR}" && make build_test_index_linux > /dev/null)
# Check if files changed, fail
if ! diff -r "${TEMP_DIR}/Tests" "Tests"; then
log_err "Linux test index is out-of-date. Please update with 'make build_test_index_linux' and commit the changes"
exit 1
else
log_success "Linux test index is up-to-date!"
fi


2 changes: 1 addition & 1 deletion Utility/stable-output-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for lang in ${lang_options[@]}; do
update_current_line "[${lang}] Testing output is stable (test case ${i}/100)"
treatment_lang_output_dir="$(mktemp -d)"
$plank_bin --lang ${lang} --output_dir=${treatment_lang_output_dir} ${json_files}
if ! diff "${lang_output_dir}" "${treatment_lang_output_dir}"; then
if ! diff -r "${lang_output_dir}" "${treatment_lang_output_dir}"; then
update_current_line "[${lang}] ❌ Output is unstable"
exit 1
fi
Expand Down

0 comments on commit 02d18ba

Please sign in to comment.