Skip to content

Commit

Permalink
Add docker for running linux tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikhsan Assaat committed Oct 2, 2018
1 parent 7f7e41e commit 51c899a
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git/
.build/
!.build/checkouts/
!.build/repositories/
!.build/workspace-state.json
6 changes: 4 additions & 2 deletions Adhan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@
0880888E2026EF910059C738 /* Astronomical.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Astronomical.swift; sourceTree = "<group>"; };
088088A22026F0390059C738 /* DateUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateUtilities.swift; sourceTree = "<group>"; };
088088B12026F0B30059C738 /* MathUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MathUtilities.swift; sourceTree = "<group>"; };
4DAB34552160D3E8006D3003 /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxMain.swift; sourceTree = "<group>"; };
4D8D12A02161883900A9A9D8 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = "<group>"; };
4D8D12A12161884500A9A9D8 /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxMain.swift; sourceTree = "<group>"; };
4DAB34592160D42B006D3003 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
84369E9F1CD03D8700C34812 /* AdhanObjc.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdhanObjc.swift; sourceTree = "<group>"; };
84482DBA1EA70A160074E53C /* QiblaTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QiblaTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -278,6 +279,7 @@
isa = PBXGroup;
children = (
4DAB34592160D42B006D3003 /* Package.swift */,
4D8D12A12161884500A9A9D8 /* LinuxMain.swift */,
8B74F4521EF55367006A51EE /* README.md */,
84F8E1211C7AB542004C48D7 /* Sources */,
84F8E12D1C7AB542004C48D7 /* AdhanTests */,
Expand Down Expand Up @@ -319,7 +321,6 @@
84F8E12D1C7AB542004C48D7 /* AdhanTests */ = {
isa = PBXGroup;
children = (
4DAB34552160D3E8006D3003 /* LinuxMain.swift */,
84BCD1AD1CB09A5900614D12 /* Times */,
84BCD1AF1CB09A7700614D12 /* TimeTests.swift */,
84F8E12E1C7AB542004C48D7 /* AdhanTests.swift */,
Expand All @@ -329,6 +330,7 @@
8B9180A61EA9BF83004C9E52 /* SunnahTests.swift */,
8480CCD81CD2DE0F00BD380B /* ObjcTests.m */,
84F8E1301C7AB542004C48D7 /* Info.plist */,
4D8D12A02161883900A9A9D8 /* XCTestManifests.swift */,
);
path = AdhanTests;
sourceTree = "<group>";
Expand Down
14 changes: 0 additions & 14 deletions AdhanTests/LinuxMain.swift

This file was deleted.

18 changes: 14 additions & 4 deletions AdhanTests/TimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ class TimeTests: XCTestCase {
}

func testTimes() {
#if os(Linux)
let fileManager = FileManager.default
let currentDir = URL(fileURLWithPath: fileManager.currentDirectoryPath)
let fixtureDir = currentDir.appendingPathComponent("Shared/Times")
let paths = try! fileManager.contentsOfDirectory(at: fixtureDir, includingPropertiesForKeys: nil)
.filter { $0.pathExtension == "json" }
#else
let bundle = Bundle(for: type(of: self))
let paths = bundle.paths(forResourcesOfType: "json", inDirectory: "Times")
.compactMap(URL.init(fileURLWithPath:))
#endif

for path in paths {
var output = "################\nTime Test Output\n"
let data = try? Data(contentsOf: URL(fileURLWithPath: path))
let data = try? Data(contentsOf: path)
let json = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSDictionary
let params = json["params"] as! NSDictionary
let lat = params["latitude"] as! NSNumber
Expand Down Expand Up @@ -94,8 +104,8 @@ class TimeTests: XCTestCase {

let variance = json["variance"] as? Double ?? 0
let times = json["times"] as! [NSDictionary]
output += "Times for \((path as NSString).lastPathComponent) - \(params["method"]!)\n"
print("Testing \((path as NSString).lastPathComponent) (\(times.count) days)")
output += "Times for \(path.lastPathComponent) - \(params["method"]!)\n"
print("Testing \(path.lastPathComponent) (\(times.count) days)")
var totalDiff = 0.0
var maxDiff = 0.0
for time in times {
Expand Down Expand Up @@ -140,7 +150,7 @@ class TimeTests: XCTestCase {
output += "\($0.1.prefix(1).capitalized): \(timeFormatter.string(from: $0.0).padding(toLength: paddingLength, withPad: " ", startingAt: 0)) JSON: \(jsonTime.padding(toLength: paddingLength, withPad: " ", startingAt: 0)) Diff: \(Int($0.2))\n"
}
}
output += "Difference for \((path as NSString).lastPathComponent) - \(params["method"]!)\n"
output += "Difference for \(path.lastPathComponent) - \(params["method"]!)\n"
output += "Average difference: \(totalDiff/Double(times.count * 6))\n"
output += "Max difference: \(maxDiff)\n"
if maxDiff > 0 {
Expand Down
80 changes: 80 additions & 0 deletions AdhanTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import XCTest

extension AdhanTests {
static let __allTests = [
("testCalculationMethods", testCalculationMethods),
("testCurrentPrayer", testCurrentPrayer),
("testMoonsightingMethod", testMoonsightingMethod),
("testMoonsightingMethodHighLat", testMoonsightingMethodHighLat),
("testNextPrayer", testNextPrayer),
("testNightPortion", testNightPortion),
("testOffsets", testOffsets),
("testPrayerTimes", testPrayerTimes),
("testTimeForPrayer", testTimeForPrayer),
]
}

extension AstronomicalTests {
static let __allTests = [
("testAltitudeOfCelestialBody", testAltitudeOfCelestialBody),
("testAngleInterpolation", testAngleInterpolation),
("testCalendricalDate", testCalendricalDate),
("testDaysSinceSolstice", testDaysSinceSolstice),
("testInterpolation", testInterpolation),
("testJulianDay", testJulianDay),
("testJulianHours", testJulianHours),
("testLeapYear", testLeapYear),
("testRightAscensionEdgeCase", testRightAscensionEdgeCase),
("testSolarCoordinates", testSolarCoordinates),
("testSolarTime", testSolarTime),
("testTransitAndHourAngle", testTransitAndHourAngle),
]
}

extension MathTests {
static let __allTests = [
("testAngleConversion", testAngleConversion),
("testClosestAngle", testClosestAngle),
("testMinuteRounding", testMinuteRounding),
("testNormalizing", testNormalizing),
("testTimeComponents", testTimeComponents),
]
}

extension QiblaTests {
static let __allTests = [
("testAsia", testAsia),
("testEurope", testEurope),
("testNorthAmerica", testNorthAmerica),
("testSouthPacific", testSouthPacific),
]
}

extension SunnahTests {
static let __allTests = [
("testSunnahTimesDST1", testSunnahTimesDST1),
("testSunnahTimesDST2", testSunnahTimesDST2),
("testSunnahTimesLondon", testSunnahTimesLondon),
("testSunnahTimesNY", testSunnahTimesNY),
("testSunnahTimesOslo", testSunnahTimesOslo),
]
}

extension TimeTests {
static let __allTests = [
("testTimes", testTimes),
]
}

#if !os(macOS)
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(AdhanTests.__allTests),
testCase(AstronomicalTests.__allTests),
testCase(MathTests.__allTests),
testCase(QiblaTests.__allTests),
testCase(SunnahTests.__allTests),
testCase(TimeTests.__allTests),
]
}
#endif
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM swift:4.2

WORKDIR /package

COPY . ./

RUN swift package resolve
RUN swift package clean
RUN swift test
8 changes: 8 additions & 0 deletions LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import XCTest

import Tests

var tests = [XCTestCaseEntry]()
tests += Tests.__allTests()

XCTMain(tests)
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let package = Package(
targets: [
.target(
name: "Adhan",
path: "Sources"
path: "Sources",
exclude: ["AdhanObjc.swift"]
),
.testTarget(
name: "Tests",
Expand Down

0 comments on commit 51c899a

Please sign in to comment.