Skip to content

Commit

Permalink
Merged PR #11: v0.4.2 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mich101mich authored Jul 21, 2024
2 parents 80d17c3 + 07f3db6 commit 886ccb9
Show file tree
Hide file tree
Showing 28 changed files with 762 additions and 262 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ jobs:
run: cargo +nightly update -Z minimal-versions
- name: Run minimal version stable tests
uses: actions-rs/cargo@v1
with: { command: test, args: -- --skip failing_tests, toolchain: stable }
with: { command: test, toolchain: stable }
- name: Run minimal version nightly tests
uses: actions-rs/cargo@v1
with: { command: test, args: -- --skip failing_tests, toolchain: nightly }
with: { command: test, toolchain: nightly }

minimum-rust-version:
runs-on: ubuntu-latest
Expand All @@ -78,4 +78,6 @@ jobs:
with: { toolchain: 1.56.0 }
- name: Run tests
uses: actions-rs/cargo@v1
with: { command: test, args: -- --skip failing_tests, toolchain: 1.56.0 }
with: { command: test, toolchain: 1.56.0 }
env:
RUSTFLAGS: "--cfg msrv_build"
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
**/target
**/*.rs.bk
Cargo*.lock
.vscode
**/target
**/Cargo.lock
/.vscode/
/test_dirs/
/wip/
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sscanf"
version = "0.4.1"
version = "0.4.2"
authors = ["mich101mich <mich101mich@gmail.com>"]
edition = "2018"
rust-version = "1.56.0"
Expand All @@ -13,12 +13,18 @@ categories = ["parsing"]
exclude = ["/.vscode/*", "/.gitignore", "/.github/*", "/*.bat", "/*.sh"]

[dependencies]
sscanf_macro = { path = "sscanf_macro", version = "=0.4.1"}
sscanf_macro = { path = "sscanf_macro", version = "=0.4.2"}
regex = "1.6.0"
const_format = "0.2.26"
lazy_static = "1.4.0"

[dev-dependencies]
trybuild = "1.0.78"
rustc_version = "0.4.0"
thiserror = "1.0.37"

[target.'cfg(not(msrv_build))'.dependencies]
const_format = "0.2.26"

[target.'cfg(msrv_build)'.dependencies]
const_format = "0.2.26,<0.2.32" # Quote from the Changelog for 0.2.32: "Breaking change: bumped Minimum Supported Rust Version to Rust 1.57"
# Writes "breaking change" and procedes to only bump the patch version 😞. Thanks.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and its wrapper crate [sscanf](https://crates.io/crates/sscanf), as neither work
and versions are always released in parallel.


## [0.4.2](https://github.com/mich101mich/sscanf/releases/tag/0.4.2) 2024-07-21

### Fixed
- Fixed `"unused variable"` in the code generated by the derive macro
- Fixed tests on 32-bit platforms ([#10](https://github.com/mich101mich/sscanf/issues/10))

## [0.4.1](https://github.com/mich101mich/sscanf/releases/tag/0.4.1) - 2023-05-20

### Added
Expand Down
6 changes: 4 additions & 2 deletions src/from_scanf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ use crate::errors::FromStrFailedError;
/// The contract is:
/// - `NUM_CAPTURES` **IS EQUAL TO**
/// - the number of consumed elements from the iterator passed to [`from_matches`](FromScanf::from_matches) **IS EQUAL TO**
/// - 1 + the number of unescaped capture groups in [`RegexRepresentation`](crate::RegexRepresentation) (or `{:/.../}`).
/// The 1 is for the whole match, which is a capture group added by `sscanf`.
/// - 1 + the number of unescaped capture groups in [`RegexRepresentation`](crate::RegexRepresentation) (or `{:/.../}`).
/// The 1 is for the whole match, which is a capture group added by `sscanf`.
///
/// All of these are automatically enforced by the derive macro or the [`FromStr`] implementation,
/// which is why they should be preferred over this option.
Expand Down Expand Up @@ -240,6 +240,8 @@ where
Self: crate::RegexRepresentation,
{
let regex = format!("^{}$", Self::REGEX);
#[allow(unused_qualifications)] // would complain about the `crate::` prefix, but we
// specifically want the bundled regex rather than whatever a user has renamed to `regex`
let regex = crate::regex::Regex::new(&regex).unwrap_or_else(|err| {
panic!(
"sscanf: Type {} has invalid RegexRepresentation `{}`: {}",
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
unstable_features,
unused_import_braces,
unused_qualifications,
rustdoc::missing_doc_code_examples,
// rustdoc::missing_doc_code_examples,
rustdoc::broken_intra_doc_links,
rustdoc::private_intra_doc_links,
rustdoc::missing_crate_level_docs,
Expand Down
8 changes: 4 additions & 4 deletions src/regex_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use const_format::formatcp;
///
/// If you do need to implement this trait yourself, note the following:
/// - The regex cannot contain any capture groups (round brackets). If you need to use `( )` in your
/// regex, use `(?: )` instead to make it non-capturing.
/// regex, use `(?: )` instead to make it non-capturing.
/// - Using a raw string literal (`r"..."`) is recommended to avoid having to escape backslashes.
/// - The [`const_format`] crate can be used to combine multiple
/// strings into one, which is useful for complex regexes. This can also be used to combine the
/// existing regex implementation of other types. `sscanf` internally uses `const_format` as well,
/// so a version of it is re-exported under `sscanf::const_format`.
/// strings into one, which is useful for complex regexes. This can also be used to combine the
/// existing regex implementation of other types. `sscanf` internally uses `const_format` as well,
/// so a version of it is re-exported under `sscanf::const_format`.
///
/// ## Example
/// Let's say we want to add a Fraction parser
Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ impl_wrapper_ops!(FullF64, f64);
///
/// ```
/// # use sscanf::*;
/// let input = "deadbeef + 0x123456789abcdef";
/// let input = "deadbeef + 0x12345abc";
/// let output = sscanf!(input, "{} + {}", HexNumber, HexNumber).unwrap();
/// assert_eq!(output.0, 0xdeadbeef);
/// assert_eq!(output.1, 0x123456789abcdef);
/// assert_eq!(output.1, 0x12345abc);
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[deprecated(
Expand Down
11 changes: 8 additions & 3 deletions sscanf_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sscanf_macro"
version = "0.4.1"
version = "0.4.2"
authors = ["mich101mich <mich101mich@gmail.com>"]
edition = "2018"
rust-version = "1.56.0"
Expand All @@ -15,8 +15,13 @@ proc-macro = true
[dependencies]
syn = { version = "2.0.1", features = ["parsing", "derive", "full"] }
quote = "1.0.0"
proc-macro2 = "1.0.0"
proc-macro2 = "1.0.60"
regex-syntax = "0.6.0"
unicode-width = "0.1.5"
strsim = "0.10.0"
convert_case = "0.6.0"

[target.'cfg(not(msrv_build))'.dependencies]
unicode-width = "0.1.5"

[target.'cfg(msrv_build)'.dependencies]
unicode-width = "0.1.5,<0.1.13" # 0.1.13 uses features which aren't supported by our MSRV of 1.56. Please standardize having an MSRVs with tests.
6 changes: 1 addition & 5 deletions sscanf_macro/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub use r#variant::*;

pub trait Attr: Debug + Display + Copy + Ord + Hash + 'static {
fn all() -> &'static [Self];
fn all_names() -> &'static [&'static str];
fn context() -> Context;

fn as_str(&self) -> &'static str;
Expand Down Expand Up @@ -89,9 +88,6 @@ macro_rules! declare_attr {
fn all() -> &'static [Self] {
Self::ALL
}
fn all_names() -> &'static [&'static str] {
Self::ALL_NAMES
}
fn context() -> super::$context_enum {
super::$context_enum::$context
}
Expand Down Expand Up @@ -283,7 +279,7 @@ fn find_attrs<A: Attr>(attrs: Vec<syn::Attribute>) -> Result<HashMap<A, Attribut
syn::Meta::NameValue(nv) => {
let msg = format!(
"attribute arguments must be in parentheses: `sscanf({})`",
nv.value.to_token_stream().to_string()
nv.value.to_token_stream()
);
return Error::err_spanned(nv, msg); // checked in tests/fail/derive_struct_attributes.rs
}
Expand Down
3 changes: 0 additions & 3 deletions sscanf_macro/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ Alternatively, you can use #[sscanf(transparent)] to derive FromScanf for a sing
fn from_matches(src: &mut ::sscanf::regex::SubCaptureMatches<'_, #lifetime>) -> ::std::result::Result<Self, Self::Err> {
let start_len = src.len();
src.next().unwrap(); // skip the whole match
let mut len = src.len();

let mut catcher = || -> ::std::result::Result<Self, ::std::boxed::Box<dyn ::std::error::Error>> {
::std::result::Result::Ok(#name #from_matches)
Expand Down Expand Up @@ -512,8 +511,6 @@ To do this, add #[sscanf(format = \"...\")] to a variant"
src.next().unwrap(); // skip the whole match
remaining -= 1;

let mut len = src.len();

let mut catcher = || -> ::std::result::Result<Self, ::std::boxed::Box<dyn ::std::error::Error>> {
#(#variant_constructors)*

Expand Down
2 changes: 0 additions & 2 deletions sscanf_macro/src/format_string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::*;

pub struct FormatString<'a> {
pub src: StrLitSlice<'a>,
pub placeholders: Vec<Placeholder<'a>>,
pub parts: Vec<String>, // contains placeholders.len() + 1 escaped parts
}
Expand Down Expand Up @@ -44,7 +43,6 @@ impl<'a> FormatString<'a> {

parts.push(current_part);
Ok(Self {
src,
placeholders,
parts,
})
Expand Down
2 changes: 2 additions & 0 deletions sscanf_macro/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

use crate::*;

/// A workaround for Spans on stable Rust.
Expand Down
159 changes: 131 additions & 28 deletions test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,34 +1,137 @@
#!/bin/bash

set -e

########
# functions
########

TMP_FILE="/tmp/sscanf_test_out.txt"
function handle_output {
rm -f "${TMP_FILE}"
while IFS='' read -r line
do
echo "${line}" >> "${TMP_FILE}"

echo -en "\033[2K\r"
echo -n "$(cut -c "1-$(tput cols)" <<< "> ${line}")"
done
echo -en "\033[2K\r";
tput init # Reset any coloring
}

function try_silent {
echo "Running $@"
unbuffer "$@" > /tmp/sscanf_test_out.txt || (cat /tmp/sscanf_test_out.txt && return 1)
echo "Running $*"
unbuffer "$@" 2>&1 | handle_output
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
cat "${TMP_FILE}"
return 1
fi
}

function assert_no_change {
DIR="$1"
if ! git diff-files --quiet --ignore-cr-at-eol "${DIR}"; then
>&2 echo "Changes in ${DIR} detected, aborting"
exit 1
fi
if [[ -n "$(git ls-files --exclude-standard --others "${DIR}")" ]]; then
>&2 echo "Untracked files in ${DIR} detected, aborting"
exit 1
fi
}

########
# setup
########
BASE_DIR="$(realpath "$(dirname "$0")")"

OVERWRITE=0
if [[ "$1" == "overwrite" ]]; then
OVERWRITE=1
elif [[ -n "$1" ]]; then
echo "Usage: $0 [overwrite]"
exit 1
fi

MSRV=$(grep '^rust-version = ".*"$' "${BASE_DIR}/Cargo.toml" | sed -E 's/^rust-version = "(.*)"$/\1/')
[[ -n "${MSRV}" ]]
echo "Minimum supported Rust version: ${MSRV}"

OUT_DIRS="${BASE_DIR}/test_dirs"
MSRV_DIR="${OUT_DIRS}/msrv_${MSRV}"
MIN_VERSIONS_DIR="${OUT_DIRS}/min_versions"

for dir in "${MSRV_DIR}" "${MIN_VERSIONS_DIR}"; do
[[ -d "${dir}" ]] && continue
mkdir -p "${dir}"
ln -s "../../Cargo.toml" "${dir}/Cargo.toml"
ln -s "../../src" "${dir}/src"
ln -s "../../tests" "${dir}/tests"
ln -s "../../sscanf_macro" "${dir}/sscanf_macro"
done

export RUSTFLAGS="-D warnings"
export RUSTDOCFLAGS="-D warnings"

########
# main tests
pushd ~/projects/sscanf
try_silent cargo update || exit 1
try_silent cargo +stable test || exit 1
try_silent cargo +nightly test || exit 1
try_silent cargo +nightly doc --no-deps || exit 1
try_silent cargo +nightly clippy -- -D warnings || exit 1
try_silent cargo +stable fmt --check || exit 1
popd

pushd ~/projects/sscanf/sscanf_macro
try_silent cargo +nightly clippy -- -D warnings || exit 1
try_silent cargo +stable fmt --check || exit 1
popd

# old rustc version
pushd ~/projects/sscanf_old_rustc
try_silent cargo +1.56.0 test -- --skip failing_tests || exit 1
popd

# minimum version
pushd ~/projects/sscanf_min_version
try_silent cargo +nightly -Z minimal-versions update || exit 1

try_silent cargo +stable test -- --skip failing_tests || exit 1
try_silent cargo +nightly test -- --skip failing_tests || exit 1
popd
########
cd "${BASE_DIR}"
try_silent rustup update
try_silent cargo update
try_silent cargo +stable test
try_silent cargo +nightly test

if [[ OVERWRITE -eq 1 ]]; then
echo "Trybuild overwrite mode enabled"
export TRYBUILD=overwrite

# "overwrite" will (as the name implies) overwrite any incorrect output files in the error_message_tests.
# There is however the problem that the stable and nightly versions might have different outputs. If they
# are simply run one after the other, then the second one will overwrite the first one. To avoid this, we
# use git to check if the files have changed after every step.
assert_no_change "tests/fail/**/*.stderr" # Check for initial changes that would skew the later checks

try_silent cargo +stable test error_message_tests -- --ignored
assert_no_change "tests/fail/**/*.stderr"

try_silent cargo +nightly test error_message_tests -- --ignored
assert_no_change "tests/fail/**/*.stderr"
else
try_silent cargo +stable test error_message_tests -- --ignored
try_silent cargo +nightly test error_message_tests -- --ignored
fi
try_silent cargo +nightly doc --no-deps
try_silent cargo +nightly clippy -- -D warnings
try_silent cargo +stable fmt --check


########
# sscanf_macro subdirectory
########
cd "${BASE_DIR}/sscanf_macro"
try_silent cargo +nightly clippy -- -D warnings
try_silent cargo +stable fmt --check

########
# minimum supported rust version
########
cd "${MSRV_DIR}"
try_silent rustup install "${MSRV}"
ORIGINAL_RUSTFLAGS="${RUSTFLAGS}"
RUSTFLAGS="${RUSTFLAGS} --cfg msrv_build"
try_silent cargo "+${MSRV}" test --tests # only run --tests, which excludes the doctests from Readme.md
RUSTFLAGS="${ORIGINAL_RUSTFLAGS}"

########
# minimum versions
########
cd "${MIN_VERSIONS_DIR}"
try_silent cargo +nightly -Z minimal-versions update

try_silent cargo +stable test
try_silent cargo +nightly test

########
echo "All tests passed!"
File renamed without changes.
Loading

0 comments on commit 886ccb9

Please sign in to comment.