-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate: warn if a date or time is in the future, fixes #8
Also add some CLI tests for various data type checks.
- Loading branch information
Showing
11 changed files
with
245 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,14 @@ philosophy. There are many features that adif-multitool could add, but they | |
should be done in harmony with the tool's philosophy. For new features or | ||
changes in behavior, please open an issue first to discuss the semantics of the | ||
feature. For straightforward bug fixes, a pull request by itself is sufficient. | ||
|
||
## Add tests | ||
|
||
It helps when bug fixes include a test case that fails without the fix. | ||
New functionality should be covered by automated tests to avoid regressions. | ||
Commands and many API functions have standard Go unit tests. There are also | ||
some tests that exercise the command line, including flag syntax parsing and | ||
checking stderr, in the [txtar](https://pkg.go.dev/golang.org/x/tools/txtar) | ||
files [in the `adifmt` package](./adifmt/testdata). These command language for | ||
these tests is described in the | ||
[testscript package](https://pkg.go.dev/github.com/rogpeppe/[email protected]/testscript). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# tests that invalid dates and times are errors | ||
! adifmt validate -output csv input.csv | ||
cmp stderr golden.err | ||
! stdout . | ||
|
||
-- input.csv -- | ||
CALL,QSO_DATE,TIME_ON,TIME_OFF,QSLSDATE | ||
K1A,2012,123,1,201206 | ||
K2B,20221032,0860,123467,9870605 | ||
K3C,2018-10-21,12:34,13:14:15,31/10/2018 | ||
K4D,November 11 2011,11pm,1111am,11111988 | ||
K5E,23450607,0000,0000,19291231 | ||
-- golden.err -- | ||
ERROR on input.csv record 1: QSO_DATE not an 8-digit date "2012" | ||
ERROR on input.csv record 1: TIME_ON not a 4- or 6-digit time "123" | ||
ERROR on input.csv record 1: TIME_OFF not a 4- or 6-digit time "1" | ||
ERROR on input.csv record 1: QSLSDATE not an 8-digit date "201206" | ||
ERROR on input.csv record 2: QSO_DATE invalid date "20221032" | ||
ERROR on input.csv record 2: TIME_ON time out of HH:MM range "0860" | ||
ERROR on input.csv record 2: TIME_OFF time out of HH:MM:SS range "123467" | ||
ERROR on input.csv record 2: QSLSDATE not an 8-digit date "9870605" | ||
ERROR on input.csv record 3: QSO_DATE invalid date "2018-10-21" | ||
ERROR on input.csv record 3: TIME_ON invalid time "12:34" | ||
ERROR on input.csv record 3: TIME_OFF invalid time "13:14:15" | ||
ERROR on input.csv record 3: QSLSDATE invalid date "31/10/2018" | ||
ERROR on input.csv record 4: QSO_DATE invalid date "November 11 2011" | ||
ERROR on input.csv record 4: TIME_ON invalid time "11pm" | ||
ERROR on input.csv record 4: TIME_OFF invalid time "1111am" | ||
ERROR on input.csv record 4: QSLSDATE invalid date "11111988" | ||
WARNING on input.csv record 5: QSO_DATE value "23450607" later than today | ||
ERROR on input.csv record 5: QSLSDATE year before 1930 "19291231" | ||
Error running validate: validate got 17 errors and 1 warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# tests that certain unknown enum values are warnings, not errors | ||
! adifmt validate -output csv input.csv | ||
cmp stderr golden.err | ||
! stdout . | ||
|
||
-- input.csv -- | ||
CALL,BAND,MODE,CONT,DXCC,STATE | ||
K1A,11m,AM,NA,291,VT | ||
K2A,20m,INVALID,NA,1,NY | ||
K3A,70CM,fm,XY,999,AB | ||
-- golden.err -- | ||
ERROR on input.csv record 1: BAND unknown value "11m" for enumeration Band | ||
ERROR on input.csv record 2: MODE unknown value "INVALID" for enumeration Mode | ||
ERROR on input.csv record 2: STATE value "NY" is not valid for DXCC="1" | ||
ERROR on input.csv record 3: CONT unknown value "XY" for enumeration Continent | ||
ERROR on input.csv record 3: DXCC unknown value "999" for enumeration DXCC_Entity_Code | ||
WARNING on input.csv record 3: STATE has value "AB" but Primary_Administrative_Subdivision doesn't define any values for DXCC="999" | ||
Error running validate: validate got 5 errors and 1 warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# tests that certain unknown enum values are warnings, not errors | ||
adifmt validate -output csv input.csv | ||
cmp stderr golden.err | ||
cmp stdout input.csv | ||
|
||
-- input.csv -- | ||
CALL,MODE,SUBMODE,CONTEST_ID,DXCC,STATE | ||
K1A,SSB,MSB,ADIF-INVALID-CONTEST,291,CT | ||
K2A,PSK,PSK123,ARRL-DIGI,,NJ | ||
3A0DX,CW,,,260,MO | ||
-- golden.err -- | ||
WARNING on input.csv record 1: SUBMODE value "MSB" is not valid for MODE="SSB" | ||
WARNING on input.csv record 1: CONTEST_ID unknown value "ADIF-INVALID-CONTEST" for enumeration Contest_ID | ||
WARNING on input.csv record 2: SUBMODE value "PSK123" is not valid for MODE="PSK" | ||
WARNING on input.csv record 2: STATE has value "NJ" but DXCC is not set | ||
WARNING on input.csv record 3: STATE has value "MO" but Primary_Administrative_Subdivision doesn't define any values for DXCC="260" | ||
validate got 5 warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# tests that invalid locations are errors | ||
! adifmt validate -output csv input.csv | ||
cmp stderr golden.err | ||
! stdout . | ||
|
||
-- input.csv -- | ||
CALL,LAT,LON,GRIDSQUARE | ||
K1A,12.345,34.567,AB12cd34 | ||
K2B,N12 34.567,W123 45.678,ZY12ab | ||
K3C,S123 45.678,X23 45.678,AB0CD | ||
K4D,N12 98.765,E12 34.56789,A01CD23 | ||
K5E,S12 12.34,W0 01.200,MN9876 | ||
K6F,S001 02.340,W000 01.200,oo00 | ||
-- golden.err -- | ||
ERROR on input.csv record 1: LAT invalid location format, make sure to zero-pad "12.345" | ||
ERROR on input.csv record 1: LON invalid location format, make sure to zero-pad "34.567" | ||
ERROR on input.csv record 2: LAT invalid location format, make sure to zero-pad "N12 34.567" | ||
ERROR on input.csv record 3: LON invalid location format, make sure to zero-pad "X23 45.678" | ||
ERROR on input.csv record 3: GRIDSQUARE odd grid square length "AB0CD" | ||
ERROR on input.csv record 4: LAT invalid location format, make sure to zero-pad "N12 98.765" | ||
ERROR on input.csv record 4: LON invalid location format, make sure to zero-pad "E12 34.56789" | ||
ERROR on input.csv record 4: GRIDSQUARE odd grid square length "A01CD23" | ||
ERROR on input.csv record 5: LAT invalid location format, make sure to zero-pad "S12 12.34" | ||
ERROR on input.csv record 5: LON invalid location format, make sure to zero-pad "W0 01.200" | ||
ERROR on input.csv record 5: GRIDSQUARE non-letter in position 4 "MN9876" | ||
Error running validate: validate got 11 errors and 0 warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# tests that out-of-range or syntactically invalid numbers are errors | ||
! adifmt validate -output csv input.csv | ||
cmp stderr golden.err | ||
! stdout . | ||
|
||
-- input.csv -- | ||
CALL,FREQ,CQZ,ITUZ,K_INDEX | ||
K1A,7.123.4,0,0,0 | ||
K2A,-14.150,-1,-1,-1 | ||
K3A,29,41,91,10 | ||
K4A,1234567,40,90,9 | ||
K5A,14.3,32.1,FF,4.0 | ||
-- golden.err -- | ||
ERROR on input.csv record 1: FREQ invalid decimal "7.123.4": strconv.ParseFloat: parsing "7.123.4": invalid syntax | ||
ERROR on input.csv record 1: CQZ value 0 below minimum 1 | ||
ERROR on input.csv record 1: ITUZ value 0 below minimum 1 | ||
ERROR on input.csv record 2: CQZ value -1 below minimum 1 | ||
ERROR on input.csv record 2: ITUZ value -1 below minimum 1 | ||
ERROR on input.csv record 2: K_INDEX value -1 below minimum 0 | ||
ERROR on input.csv record 3: CQZ value 41 above maximum 40 | ||
ERROR on input.csv record 3: ITUZ value 91 above maximum 90 | ||
ERROR on input.csv record 3: K_INDEX value 10 above maximum 9 | ||
ERROR on input.csv record 5: CQZ invalid integer "32.1" | ||
ERROR on input.csv record 5: ITUZ invalid number "FF" | ||
ERROR on input.csv record 5: K_INDEX invalid integer "4.0" | ||
Error running validate: validate got 12 errors and 0 warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters